I have a touch script where if you touch the part, it takes a model from repstore and parents it to workspace, sort of like a regen button. problem is that, when you touch it, it keeps on spawning the item from repstore constantly until you step off the block. help.
parent = script.Parent function onTouch(hit) wait(1) local ItemInStorage = game.ReplicatedStorage.Floaty; local P = ItemInStorage:Clone(); P.Parent = workspace; wait(10) game.Workspace.Floaty:Destroy() end parent.Touched:connect(onTouch)
You might want to add a debounce, or a cooldown in other words, so It might look like this
local debounce = false parent = script.Parent function onTouch(hit) if debounce == false then debounce = true wait(1) local ItemInStorage = game.ReplicatedStorage.Floaty; local P = ItemInStorage:Clone(); P.Parent = workspace; wait(10) game.Workspace.Floaty:Destroy() end wait(10)--change this number to how long you want the cooldown to be debounce = false end parent.Touched:connect(onTouch)
Forgive me if I'm wrong, I'm pretty new to coding myself, but this should work