Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by
yoshi8080 445 Moderation Voter
8 years ago

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

Log in to vote
-1
Answered by 8 years ago

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.

0
attempt to index local 'animation' (a nil value) yoshi8080 445 — 8y
0
Seriously? I provided you with the fixes to your code. You should have taken them and put them into your code. LetThereBeCode 360 — 8y
0
I did yoshi8080 445 — 8y
Ad

Answer this question