I created 3 animations and tool (sword) and now I want it to be like when you click with mouse it randomly chooses and plays one of these animations. (my scripting skills are very low) my current script:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local randomAnimation = math.random(1,3)
if randomAnimation == 1 then
local animation = script.Parent:FindFirstChild("Animation1")
local swingAnimation = character.Humanoid:LoadAnimation(animation)
local canSwing = true
local debounce = 0.5
script.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
swingAnimation:play()
wait(debounce)
canSwing = true
end
end)
elseif randomAnimation == 2 then
local animation = script.Parent:FindFirstChild("Animation2")
local swingAnimation = character.Humanoid:LoadAnimation(animation)
local canSwing = true
local debounce = 0.5
script.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
swingAnimation:play()
wait(debounce)
canSwing = true
end
end)
elseif randomAnimation == 3 then
local animation = script.Parent:FindFirstChild("Animation3")
local swingAnimation = character.Humanoid:LoadAnimation(animation)
local canSwing = true
local debounce = 0.5
script.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
swingAnimation:play()
wait(debounce)
canSwing = true
end
end)
end

3 comments
Thank you, this really helped me!
np! since it helped, i would appreciate if you accepted the answer.
sorry but I don't know how, when I will found out I will 100% do it.