Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Value Changed event not disabling?

Asked by 4 years ago

I have this script which reads if a value is changed to 1, and if it is then it kills you and plays a noise. However when the value is changed to 1, and then back to 0, this script stays active and keeps killing and playing noises when the parent block is touched. Is there any event or function I can do so that it disables when changed back to 0?

local yo = script.Parent.Parent.yo
local debounce = false
yo.Changed:Connect(function(newval)  --event im using to trigger this,  doesnt work as intended, any better alternatives for my situation?
if newval==1 then           -- this too
        script.Parent.Touched:Connect(function(hit)
            if debounce==false then
                local h = hit.Parent.Humanoid
                        if h.health>0 then
                        debounce=true
                        h.Health = 0
                        script.Parent.Parent.SoundPlayer.honk:Play()
                        wait(1)
                        debounce=false  
                        end

                end
            end)
elseif newval==0 then --attempt to make the script not work when value is 0
    print('safe')

end
end)

0
Try adding a boolvalue to line 6 that needs to be true then make that value false in line 20 and true in line 5 OBenjOne 190 — 4y

Answer this question