Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i stop a script from playing multiple times?

Asked by
o_xul 0
5 years ago

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)
0
Use a debounce. DeceptiveCaster 3761 — 5y
0
this code is also bad, cause it uses remove and connect which are deprecated, and its not indented either LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
   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

0
I'd say that that is perfect for what @o_xul needs. GamingZacharyC 152 — 5y
0
I'd say that that is horrible code for what @o_xul needs. User#24403 69 — 5y
Ad

Answer this question