I have a blade that has 5 random animations that can play if you press ur mouse button or tap ur screen using math.random and the animations don’t look the best because I can’t animate the tool it’s self only the hand moving and the tool sticking to it how could I animate wifh moter6d without messing up my random animations that play?
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local animation1 = script.Parent:FindFirstChild(“Animation1”)
local animation2 = script.Parent:FindFirstChild(“Animation2”)
local animation3 = script.Parent:FindFirstChild(“Animation3”)
local animation4 = script.Parent:FindFirstChild(“Animation4”)
local animation5 = script.Parent:FindFirstChild(“Animation5”)
local swingAnimation1 = character.Humanoid:LoadAnimation(animation1)
local swingAnimation2 = character.Humanoid:LoadAnimation(animation2)
local swingAnimation3 = character.Humanoid:LoadAnimation(animation3)
local swingAnimation4 = character.Humanoid:LoadAnimation(animation4)
local swingAnimation5 = character.Humanoid:LoadAnimation(animation5)
local debounce = 3
local canSwing = true
script.Parent.Activated:Connect(function()
local Swing = math.random(1,5)
if Swing == 1 and canSwing == true then
canSwing = false
swingAnimation1:Play()
wait(debounce)
canSwing = true
else if Swing == 2 and canSwing == true then
canSwing = false
swingAnimation2:Play()
wait(debounce)
canSwing = true
else if Swing == 3 and canSwing == true then
canSwing = false
swingAnimation3:Play()
wait(debounce)
canSwing = true
else if Swing == 4 and canSwing == true then
canSwing = false
swingAnimation4:Play()
wait(debounce)
canSwing = true
else if Swing == 5 and canSwing == true then
canSwing = false
swingAnimation5:Play()
wait(debounce)
canSwing = true
end
end
end
end
end
end)
Idk why it shows up like that but that’s script
properly formatted code block
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local animation1 = script.Parent:FindFirstChild("Animation1")
local animation2 = script.Parent:FindFirstChild("Animation2")
local animation3 = script.Parent:FindFirstChild("Animation3")
local animation4 = script.Parent:FindFirstChild("Animation4")
local animation5 = script.Parent:FindFirstChild("Animation5")
local swingAnimation1 = character.Humanoid:LoadAnimation(animation1)
local swingAnimation2 = character.Humanoid:LoadAnimation(animation2)
local swingAnimation3 = character.Humanoid:LoadAnimation(animation3)
local swingAnimation4 = character.Humanoid:LoadAnimation(animation4)
local swingAnimation5 = character.Humanoid:LoadAnimation(animation5)
local debounce = 3
local canSwing = true
script.Parent.Activated:Connect(function()
local Swing = math.random(1,5)
if Swing == 1 and canSwing == true then
canSwing = false
swingAnimation1:Play()
wait(debounce)
canSwing = true
else if Swing == 2 and canSwing == true then
canSwing = false
swingAnimation2:Play()
wait(debounce)
canSwing = true
else if Swing == 3 and canSwing == true then
canSwing = false
swingAnimation3:Play()
wait(debounce)
canSwing = true
else if Swing == 4 and canSwing == true then
canSwing = false
swingAnimation4:Play()
wait(debounce)
canSwing = true
else if Swing == 5 and canSwing == true then
canSwing = false
swingAnimation5:Play()
wait(debounce)
canSwing = true
end
end
end
end
end
end)
Using a table would greatly shorten your code.
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local swingAnimations = {}
for i = 1, 5 do
local animationName = "Animation" .. i
local animation = script.Parent:FindFirstChild(animationName)
swingAnimations[i] = humanoid:LoadAnimation(animation)
end
local debounce = 3
local canSwing = true
script.Parent.Activated:Connect(function()
local Swing = math.random(1, 5)
local swingAnimation = swingAnimations[Swing]
if canSwing == true then
canSwing = false
swingAnimation:Play()
wait(debounce)
canSwing = true
-- I would say use "elseif" instead of "else if"
-- but the table removes the need
end
end)
I personally don’t know much about animating tools, but there are resources on the dev forum for it!