Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my punch script not playing animation?

I want to make a script that plays a punch animation when M1 is clicked and fires a remote event, this is what i have but for some reason the animation is not playing when the button is pressed. I do own the animation and there are no errors

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local event = game.ReplicatedStorage:WaitForChild("Punch")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local AnimationId = 6214482685

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..AnimationId

local AnimationTrack = Humanoid:LoadAnimation(Animation)

local function Punch()
	if not (AnimationTrack.Stopped) then return end
	event:FireServer()
	AnimationTrack:Play()
end

Mouse.Button1Down:Connect(Punch)

1 answer

Something that seems funny in your code is AnimationTrack.Stopped. Looking on the developer website, it says that AnimationTrack.Stopped is a function, not a boolean. So the if statement most likely returns before it does anything.

A good fix for this would be animationtrack.isPlaying.

Here is how to fix I think:

if (AnimationTrack.isPlaying) then return end

This discussion is preserved as it was. New answers, comments, and votes are closed.