I’ve tried multiple other posts on the forum but none of them worked since my script is slightly different then most, right now the sword only has one animation but I’m trying to add a random chance to play multiple different animations and I have no idea how to go about it or write it also for some reason putting the animation in a folder causes the swing animation to not play it could just be something I’m doing wrong but I’m not sure.
Here is the script and animations thanks
local tool = script.Parent
local player = nil
local players = game:GetService("Players")
local char = nil
local mouse = nil
local connection = nil
local IdleAnim = tool:WaitForChild("Idle")
local idleTrack = nil
local AttackTrack = nil
local AttackAnim = tool:WaitForChild("Attack")
local function onIdle(char, equipped)
if not char then
return
end
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
if equipped then
idleTrack = animator:LoadAnimation(IdleAnim)
idleTrack:Play()
local speed = hum.WalkSpeed
elseif idleTrack then
idleTrack:Stop()
idleTrack:Destroy()
idleTrack = nil
end
end
local function onActivated()
if not char then
return
end
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
if AttackTrack then
return
end
AttackTrack = animator:LoadAnimation(AttackAnim)
AttackTrack:Play()
task.wait(1.5)
AttackTrack:Stop()
AttackTrack:Destroy()
AttackTrack = nil
end
local function onEquipped()
char = tool.Parent
player = players:GetPlayerFromCharacter(char)
if not player then
return
end
mouse = player:GetMouse()
connection = tool.Activated:Connect(onActivated)
onIdle(char, true)
end
local function onUnequipped()
player = nil
mouse = nil
connection:Disconnect()
onIdle(char, false)
char = nil
end
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
