I’m trying to add a wait timer to my spleif game script so that you don’t fall instantly when you touch a brick.
Here’s the script:
local spleif = script.Parent
function onTouch(hit)
if not hit.Parent:findFirstChild("Humanoid") then return end
spleif.Transparency = (.65)
spleif.CanCollide = false
wait(7.5)
spleif.Transparency = (0)
spleif.CanCollide = true
end
spleif.Touched:Connect(onTouch)
That is for making the brick re-appear after you step on it. I’m trying to make something like this:
local spleif = script.Parent
function onTouch(hit)
wait(1) <-------
if not hit.Parent:findFirstChild("Humanoid") then return end
spleif.Transparency = (.65)
spleif.CanCollide = false
wait(7.5)
spleif.Transparency = (0)
spleif.CanCollide = true
end
spleif.Touched:Connect(onTouch)
You just add it. Also, adding a debounce is also important to make sure the part doesn’t appear and dissapear repetitively, because when an event is fired, a new thread is created to handle that callback function which handled the fired event.
Set a variable outside of the function set to false.
When the block is touched, check if the debounce var is false. If yes, carry on.
At the end of the function set the debounce to true again.
Ex:
local debounce = false
local spleif = script.Parent
function onTouch(hit)
if not debounce then
doThingsHere()
wait(5)
reset()
debounce = false
end
end
spleif.Touched:Connect(onTouch)
local spleif = script.Parent
local debounce = false
function onTouch(hit)
if not debounce then
debounce = true
wait(1) <-------
if not hit.Parent:findFirstChild("Humanoid") then return end
spleif.Transparency = (.65)
spleif.CanCollide = false
wait(7.5)
spleif.Transparency = (0)
spleif.CanCollide = true
debounce = true
end
spleif.Touched:Connect(onTouch)