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

Speedcoil giver gives multiple speed coils every time touched?

i am not very good at scripting so i need a little help. The item giver i made gives a speedcoil to the person who touched it. But the problem is every time the character touched it, it adds another speed coil to the inventory. things to know --- Speed coil is in server storage

local plr = game.Players.LocalPlayer
if plr.Backpack:FindFirstChild('SpeedCoil') or plr.StarterGear:FindFirstChild('SpeedCoil') or game.Workspace[plr.name]:FindFirstChild('SpeedCoil') then
	game.ServerStorage.SpeedCoil:Destroy()
	
end

1 answer

What you are looking for is called a Debounce! As in No bouncing! It's what programmers use to account for the microsopic bounces that happen with buttons, touch evens it game, ect..

The most common way to fix this is simple!

local debounce -- this is what we are using!
script.Parent.Touched:Connect(function() -- simple example touched function
if debounce then return end -- this says, If debounce (or "is bouncing") then stop the script.
debounce = true -- if debounce isnt true then lets make it true
print"touched"
wait(0.5) -- cool down of 0.5 seconds between touches!
debounce = nil -- turn off boucning so it can be used again
end

1 comment

0

Since the Giver i made is kind of different than just a touch the front giver, i am not sure a debounce would work for it since it has many complicated parts held together by one script. So basically when i put this script in the parent i would think would suit it, it wouldnt work.

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