So im very new to scripting and im trying to make a block that becomes slowly more transparent when you step on it, and then deletes itself. now the script works fine but the problem is if i keep walking on the block it will play the script again and the transparency will crazy for a second and then it deletes the block. heres the script.
function touch(hit) wait (0.3) game.Workspace.disapear.Transparency = 0.5 wait (0.3) game.Workspace.disapear.Transparency = 0.75 wait (0.3) script.Parent:remove() end script.Parent.Touched:connect(touch)
debounce = false script.Parent.Touched:Connect(function(hit)--when you touch the part it connects the hit.parent function if hit.Parent:FindFirstChild("the part of the player u want to look for in here")-looks for the player part if not debounce then--if debounce is false then it runs the lines of code debounce = true-- sets it to true so it wont run again wait (0.3) game.Workspace.disapear.Transparency = 0.5 wait (0.3) game.Workspace.disapear.Transparency = 0.75 wait (0.3) script.Parent:remove() end wait(1) debounce = false--sets it back to false after 1 second so the code can run again, you can ofcourse change the wait() value higher for a higher waiting time end
that is a code i use alot in my games and it works perfectly