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

Tool animation (when its activated) did not play?

i want to make a sword that plays its animation when its activated. Im actually bad at creating weapons so i used this tutorial.

https://www.youtube.com/watch?v=sC84mj1-h9Y

Weapon animation plays only when the tool is picked up from workspace, but it's animation is not working when it's in starterpack.

Error message: Players.me.Backpack.Script:6: attempt to index nil with 'Character' - Server - Script:6

Im posting the script below.

wait(4)



local player = game:GetService("Players").LocalPlayer
local character = player.Character
local animation = script.Parent:FindFirstChild("Animation")
local swingAnimation = character.Humanoid:LoadAnimation(animation)

local canSwing = true

local debounce = 1

script.Parent.Activated:Connect(function()
	if canSwing then
		canSwing = false
		swingAnimation:Play()
		wait(debounce)
		canSwing = true
	end
end)

1 answer

✓ Accepted answer

Server scripts can't get the local player. Put the code into a local script.

6 comments

0

i already did it but it did not work

0

What error are you getting now

0

The script has to be in a local script. Run the script with the code in a local script and tell me what error you're getting

0

Oh! wait it works, i just forgot refresh, thanks!

0

bruh lol. accept my invite pls so i can get them sweet rep points

0

ok lol

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