Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Attempted to Index nil With Character?

Asked by 1 month 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 24 — 1mo
0
ani is in the click detector function thing but your looking for it in a place it isnt cjkizzy286 24 — 1mo
0
You are trying to interact with something that doesnt exist. robloxbubbymm 3 — 1mo
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 5747 — 1mo
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 5747 — 1mo
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 5747 — 1mo

1 answer

Log in to vote
1
Answered by 1 month 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