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)

1 comment
You Are the 123456th Person Who Questioned!