I am currently working on a game and when you use a tool it will play an animation and pick randomly from a table but the issue is that you can use the tool multiple times and it would pick more then one item from the table and play the animation multiple times. The animation also uses the tool as a prop so it can't be deleted. How would I approach making it so you still have the tool but the function only runs once?
tool = script.Parent handle = tool:WaitForChild("Handle") plr = game.Players.LocalPlayer tool.Activated:Connect(function() local Stands = { "StarPlatinum", "TheWorld" } --The names of the stands local anim = Instance.new("Animation", plr.Character) anim.AnimationId = "http://www.roblox.com/asset/?id=6813851472" local pAnim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(anim) local value = math.random(1,2) --the second number is the amount of stands in the table. if you add a new stand change this number. local pickedValue = Stands[value] print(tostring(pickedValue)) pAnim:Play() wait(3) tool:Destroy() pAnim:Stop() end)
You could add this line at the start of the script:
local itemUsed = false
And in the function you put everything in this "if" statement:
if not itemUsed then -- Everything from line 7 to line 27 end
And at line 28 you add this:
itemUsed = true
Hope this helps!
You can set Tool.Enabled to false if you do not want the Activated event to be fired again.