So I have ascript.Parent.Touched:Connect(function(hit)
function that makes a block fade in, but it keeps on running even if it's in the middle of running. I want it to only run once and then keep the block visible. How would I do this?
Debounce! Debounce doesn't allow a function to run again until a set time has passed.
My example of Debounce;
local Part = script.Parent local Debounce = false Part.Touched:Connect(function(hit) if Debounce == false then Debounce = true print("This cannot run again until 5 seconds have passed!") wait(5) Debounce = false end end)
If you want it to run only ONCE, then use connections and disconnect them.
local Part = script.Parent local Connection Connection = Part.Touched:Connect(function(hit) --Code Connection:Disconnect() end)
function onTouched(hit) -- code connection:Disconnect() end local connection = script.Parent.Touched:Connect(onTouched)
or
script.Parent.Touched:Wait() -- code