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

Speedcoil giver gives multiple speed coils every time touched?

Asked by 7 years ago

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

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

1 answer

Log in to vote
3
Answered by
Bellyrium 310 Moderation Voter
7 years ago

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!

1local debounce -- this is what we are using!
2script.Parent.Touched:Connect(function() -- simple example touched function
3if debounce then return end -- this says, If debounce (or "is bouncing") then stop the script.
4debounce = true -- if debounce isnt true then lets make it true
5print"touched"
6wait(0.5) -- cool down of 0.5 seconds between touches!
7debounce = nil -- turn off boucning so it can be used again
8end
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. sweetlittlegirlohhl -22 — 7y
Ad

Answer this question