This is what's happening https://gyazo.com/c87afac7a2c901e4acfaea31d6f60a5a
this is my script
p = script.Parent function off (hit) local e = hit.Parent local humanoid = e:FindFirstChildWhichIsA("Humanoid") if ( humanoid ) then b = game.ServerStorage.a:Clone() b.Parent = game.Workspace end end p.Touched:Connect(off)
I only want it to clone once when I'm touching the the scripts parent and only to clone another if I stopped touching the part and retouched it.
What am I doing wrong?
You can debounce. A quick example of debouncing with the Part.Touched event:
local debounce = false local somePart = workspace.Part somePart.Touched:Connect(function(hit) if not debounce then -- now we just set debounce to true -- this prevents the code below from being executed too quickly debounce = true -- put your code after that print(hit.Name .. ' touched a part!') -- then we wait (in this example, one second) -- and we set debounce back to false wait(1) debounce = false end end)
What does this do? Basically, by setting debounce to true
, we are preventing the code from being executed too fast. The wait
at the end is the delay until the code within the if
block can be executed again.