Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i stop a script from playing multiple times?

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)

2 comments

0

Use a debounce.

0

this code is also bad, cause it uses remove and connect which are deprecated, and its not indented either

1 answer

   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

2 comments

0

I'd say that that is perfect for what @o_xul needs.

0

I'd say that that is horrible code for what @o_xul needs.

This discussion is preserved as it was. New answers, comments, and votes are closed.