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

attempt to index local 'Humanoid' (a nil value), how do i fix this?

error: attempt to index local 'Humanoid' (a nil value)

script.Parent.Handle.Remotes.Detain.OnServerEvent:Connect(function(Suspect)
local Humanoid = Suspect:FindFirstChild("Humanoid")

local Animation = Humanoid:LoadAnimation(script.Parent.Handle.Animations.Detained)
Animation:Play()

end)

1 comment

0

Suspect is the player btw

1 answer

✓ Accepted answer

Your "Suspect" variable is probably a variable for a player in the "Players" services. To fix that, you need to find the player in the workspace:

local Humanoid = game.Workspace:FindFirstChild(Suspect):FindFirstChild("Humanoid")

I hope this worked for you. -- Toby

9 comments

0

im getting the error 'attempt to index a nil value' on that

0

Try with ":FindFirstChild(Suspect.Name)" instead of ":FindFirstChild(Suspect)". Does that work?

0

I'm getting no errors, the animation isn't playing tho

0

Just checking the ID

0

Try and look at the code at the button of this page: https://developer.roblox.com/en-us/api-reference/class/Animation

0

Alright. The script works great now. However, the animation is played on me, rather than the Mouse.Target

0

If you pressed it, then it, should, plays on you.

0

Suspect = Mouse.Target.Parent (the target is Humanoidrootpart)

0

Rip.

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