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

Attempted to Index nil With Character?

Asked by 3 years ago

I am trying to make an animation when you pick up stuff but it keeps saying:

Workspace.Part.Script:2: attempt to index nil with 'Character'

script.Parent.ClickDetector.MouseClick:Connect(function()
    local ani = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Pickup)
    ani:Play()
end)
0
it cant find ani thats why cjkizzy286 40 — 3y
0
ani is in the click detector function thing but your looking for it in a place it isnt cjkizzy286 40 — 3y
0
You are trying to interact with something that doesnt exist. robloxbubbymm 3 — 3y
1
Server-sided Scripts aren't localized, obviously, therefore no pointer exists to a linked Client Instance. Fortunately, the MouseClick RBXScriptSignal provides a parameter that refers to the Player Object of the user that clicked, so you can simply utilize that. Ziffixture 6913 — 3y
View all comments (2 more)
1
CJ, "ani" is short for "Animation". It's a variable used to reference the AnimationTrack Object that's returned by the :LoadAnimation() method of Humanoid. Ziffixture 6913 — 3y
1
If you don't need to reference the Object anywhere else, Error_404, then declaring a variable is redundant. You can directly call the :Play() method onto :LoadAnimation() due to it's Object-return. Ziffixture 6913 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Local player cannot be used in Server Sided script. However, you can utilize the first parameter of a click which is the player who clicked it. Try this out:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    local ani = plr.Character.Humanoid:LoadAnimation(script.Parent.Pickup)
    ani:Play()
end)
Ad

Answer this question