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

I can't seem to get this tool script to work?

I want the tool to play an animation once clicked, help?

local Tool = script.Parent;
enabled = true




function onActivated(player)
	if not enabled  then
		return
	end

	enabled = false
local animation = player:FindFirstChild("Humanoid")
local rawr = Tool:FindFirstChild("DrinkAnimation")
animation:LoadAnimation(rawr)


	Tool.Handle.DrinkSound:Play()

	enabled = true

end

function onEquipped()
print("Equipped")
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

error: attempt to index local 'player' (a nil value) any way to make this work?

1 answer

Activated event of Tool doesn't pass the Player as argument. What you need to do is access local player on start of your code.

wait(0.1) -- This is a good convention to make sure client variables have loaded
local player = game.Players.LocalPlayer

Then, use that player variable instead.

The second problem is that you are only loading the animation. What :LoadAnimation does, it creates an AnimationTrack which you need to play.

local rawrAnim = animation:LoadAnimation(rawr)
rawrAnim:Play()

Hope this helped.

3 comments

0

attempt to index local 'animation' (a nil value)

0

Seriously? I provided you with the fixes to your code. You should have taken them and put them into your code.

0

I did

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