So, I have a gun tool. It's meant to reload when you press R. However, when you put the tool away and take it out again, it will fire the function twice, then three times, and so on. How would I prevent this?
Here's my code.
tool.Equipped:connect(function(mouse)
--Tool equipped
toolEquipped = true
mouse.Icon = "http://www.roblox.com/asset?id=" .. mouseIcon
local character = player.Character
local Humanoid = character.Humanoid
animTrack = character.Humanoid:LoadAnimation(holdGun)
animTrack:Play()
local ammoDisplay = player.PlayerGui:WaitForChild("ammoDisplay")
ammoDisplay.Frame.ammo.Text = scriptLoaded .. "/" .. scriptUnloaded
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
end)

2 comments
Use a debounce
cause u write animTrack:play() but u need to write somewhere else AnimTrack:Stop() or it loop