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

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

Asked by
u1v6 22
5 years ago

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)
0
Suspect is the player btw u1v6 22 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

0
im getting the error 'attempt to index a nil value' on that u1v6 22 — 5y
0
Try with ":FindFirstChild(Suspect.Name)" instead of ":FindFirstChild(Suspect)". Does that work? tobiO0310 58 — 5y
0
I'm getting no errors, the animation isn't playing tho u1v6 22 — 5y
0
Just checking the ID u1v6 22 — 5y
View all comments (5 more)
0
Try and look at the code at the button of this page: https://developer.roblox.com/en-us/api-reference/class/Animation tobiO0310 58 — 5y
0
Alright. The script works great now. However, the animation is played on me, rather than the Mouse.Target u1v6 22 — 5y
0
If you pressed it, then it, should, plays on you. tobiO0310 58 — 5y
0
Suspect = Mouse.Target.Parent (the target is Humanoidrootpart) u1v6 22 — 5y
0
Rip. tobiO0310 58 — 5y
Ad

Answer this question