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

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

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!

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
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