Making when someone walks with the sword, animation plays.
Problem is, the animation always plays, and its kind of random if it plays or not.
I’ve looked around youtube for a bit of help.
Here’s my code
local animation = script:WaitForChild("Animations")
local idle = animation:WaitForChild("Idle")
local run = animation:WaitForChild("Run")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local Humanoid = char:WaitForChild("Humanoid")
local track = char.Humanoid:LoadAnimation(idle)
local animtrack = Humanoid:LoadAnimation(run)
track.Looped = true
local weld
local function handleWalkAnim()
if Humanoid.MoveDirection ~= Vector3.new() and not animtrack.IsPlaying then
animtrack:Play()
elseif Humanoid.MoveDirection == Vector3.new() and animtrack.IsPlaying then
animtrack:Stop()
end
end
script.Parent.Equipped:Connect(function()
track:Play()
handleWalkAnim()
end)
script.Parent.Unequipped:Connect(function()
track:Stop()
end)
game.ReplicatedStorage.Remotes.Jam.OnClientEvent:Connect(function()
game.Workspace.Folder.Courage:Play()
end)
local RunService = game:GetService("RunService")
local renderSteppedConn
local animation = script:WaitForChild("Animations")
local idle = animation:WaitForChild("Idle")
local run = animation:WaitForChild("Run")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local Humanoid = char:WaitForChild("Humanoid")
local track = char.Humanoid:LoadAnimation(idle)
local animtrack = Humanoid:LoadAnimation(run)
track.Looped = true
local weld
local function handleWalkAnim()
if Humanoid.MoveDirection ~= Vector3.new() and not animtrack.IsPlaying then
animtrack:Play()
elseif Humanoid.MoveDirection == Vector3.new() and animtrack.IsPlaying then
animtrack:Stop()
end
end
script.Parent.Equipped:Connect(function()
track:Play()
renderSteppedConn = RunService.RenderStepped:Connect(handleWalkAnim)
renderSteppedConn:Disconnect()
renderSteppedConn = nil
end)
script.Parent.Unequipped:Connect(function()
track:Stop()
end)
game.ReplicatedStorage.Remotes.Jam.OnClientEvent:Connect(function()
game.Workspace.Folder.Courage:Play()
end)