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

Sword animation Play Error from local scrip and made animation?

Hello, I am trying to load an animation by script. This is my LocalScript...

local CanAttack = true

script.Parent.Equipped:Connect(function()
	local AttackL1 = script.AttackAnimationSwordL1
	local IdleL1 = script.IdleL1
	
	IdleL1:Play()
end)

script.Parent.Activated:Connect(function()
	local AttackL1 = script.AttackAnimationSwordL1
	local IdleL1 = script.IdleL1
	
	if CanAttack == true then
		AttackL1:Play()
		IdleL1:Stop()
		wait(1)
		CanAttack = false
		AttackL1:Stop()
		IdleL1:Play()
		CanAttack = true
		script.Parent.CanDamage.Value = true
	end
end)

For some reason I get this error message and the script doesn't work. This is a scrpit that I found on youtube of 2017 so it might be outdated but I don't think Play() is I need help fixing this scrpit. this is the error message I get

Play is not a valid member of Animation

4 comments

0

hi, may i know which line does the error belong to?

0

it is different every time but its the lines where I wrote Value:Play()

0

Is there any error for AttackL1:Play() ? Because i think the error is with IdleL1:Play().

0

yes both if I keep the sword out it gives me error of IdleL1:Play() and when I click with the sword I get the AttackL1:Play()

1 answer

✓ Accepted answer

The problem with your script is that you haven't loaded the Animations yet. Animations are required to be loaded in order for them to be played.

You can do this using Humanoid:LoadAnimation()

-- This is assuming your Script is inside a Tool object.
local humanoid = script.Parent.Humanoid
local CanAttack = true

-- Load the animations to be used later
local AttackL1 = humanoid:LoadAnimation(script.AttackAnimationSwordL1)
local IdleL1 = humanoid:LoadAnimation(script.IdleL1)

script.Parent.Equipped:Connect(function()
    IdleL1:Play()
end)

script.Parent.Activated:Connect(function()
    if CanAttack == true then
        AttackL1:Play()
        IdleL1:Stop()
        wait(1)
        CanAttack = false
        AttackL1:Stop()
        IdleL1:Play()
        CanAttack = true
        script.Parent.CanDamage.Value = true
    end
end)

If this solves your problem, make sure to accept the answer!

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