local platform = script.Parent
local debounce = false
local function hit()
if debounce then
debounce = true
platform.Transparency = 0.5
wait(5)
platform.Transparency = 0
debounce = false
end
end
platform.Touched:Connect(hit)
Remove the local before function hit(). Also what @Rynappel said, you logic is flipped. You can use if not debounce or change debounce to be true and flip the other assignments.
local platform = script.Parent
local debounce = true
function hit()
if debounce then
debounce = true
platform.Transparency = 0.5
wait(5)
platform.Transparency = 0
debounce = false
end
end
platform.Touched:Connect(hit)
Your OP with the script was checking if the debounce was equal to true, but since you had it at false when you first defined it the if statement just skipped through the rest of the function
Next time, try debugging your self to see if you can solve it, like this:
local platform = script.Parent
local debounce = false
local function hit()
print("Function Hit Fired")
if debounce then
print("Debounce = true")
debounce = true
platform.Transparency = 0.5
wait(5)
platform.Transparency = 0
debounce = false
end
end
platform.Touched:Connect(hit)
Then you could see “Debounce is true” didnt print, and hopefully spot it.
That just basically means the opposite of what you’re trying to check
Like if I put this:
local Yes = true
if not Yes then --This won't pass through because Yes is equal to true, and not false
print(Yes)
end
if Yes then --This will pass however since Yes is equal to true (Yes = true)
print(Yes)
end