#why is my script not interacting with my boolvalue object

22 messages · Page 1 of 1 (latest)

knotty mauve
#

i have a script that gets cloned into multiple objects. problem is the script is meant to check is a boolvalue called debounce disabled but it only checks it once and doesn't even change the value. The only times it checks is on game start. The script is a server script running in objects in workspace.

local AttackPoint = workspace.Base
local Health = workspace.Base.Health
local Char = script.Parent

local debounce = workspace.Base.Debounce.Value
local debounceTime = 5
local raycastParams = RaycastParams.new()
local range = 10

raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {script.Parent}

while task.wait(0.1) do
    local raycast = workspace:Raycast(Char.PrimaryPart.Position, (AttackPoint.Position - Char.PrimaryPart.Position).Unit * range, raycastParams)

    if raycast then
        local hitPart = raycast.Instance

        if hitPart then
            if hitPart.Name == AttackPoint.Name then

                if debounce == false then
                    debounce = true
                    Health.Value -= 10
                    task.wait(debounceTime)
                    debounce = false
                end
            end
        end
    end
end
faint merlin
#

wait

#

local AttackPoint = workspace.Base
local Health = workspace.Base.Health
local Char = script.Parent

local debounceObj = workspace.Base.Debounce -- Reference to the BoolValue
local debounceTime = 5
local raycastParams = RaycastParams.new()
local range = 10

raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {script.Parent}

while task.wait(0.1) do
local raycast = workspace:Raycast(Char.PrimaryPart.Position, (AttackPoint.Position - Char.PrimaryPart.Position).Unit * range, raycastParams)

if raycast then
    local hitPart = raycast.Instance

    if hitPart and hitPart.Name == AttackPoint.Name then
        if debounceObj.Value == false then  -- Directly check the BoolValue
            debounceObj.Value = true  -- Change the actual BoolValue
            Health.Value -= 10
            task.wait(debounceTime)
            debounceObj.Value = false  -- Reset the BoolValue
        end
    end
end

end

#

copy this script

keen cape
#

hmmm

#

okk

faint merlin
#

its should work i thin

#

think

keen cape
#

yeah

#

it should work

#

the problem was here local debounce = workspace.Base.Debounce.Value

#

bc you wanted to store the initial value

keen cape
#

it stores the initial value and the actual value

#

so u done it by your self

knotty mauve
#

ye it works now thanks

faint merlin
#

np

#

thats nice to hear

keen cape
#

oh

knotty mauve
#

originally i had that but changed it to the one i showed you because i got the error attempt to index boolean with Value

keen cape
knotty mauve
#

that is fixed now though