So, I have a slight dilemma.
I've scripted a tool that finds the humanoid from a mouse.Target value. It locates the parent of whatever was clicked, then finds the child of humanoid.
My issue is, the script only works sometimes. On the game I coded it on, it worked brilliantly. Every time, no issues.
However, when I inserted it (I made sure I inserted everything) into the game which it was being used for, it worked once, then broke. Wouldn't detect the humanoid whatsoever.
These are the errors I received.
"Humanoid is not a valid member of part."
No clue why it says part, I added a line of code to print whatever was clicked, and it said Torso/Left Arm/ etc. As it should.
Anyone know why?
This is the script:
script.Parent.Equipped:connect(function(m)
m.Button2Down:connect(function()
local humanoid=m.Target.Humanoid
if humanoid then
local plr=game.Players:GetPlayerFromCharacter(humanoid.Parent)
game.ReplicatedStorage.Systems.CuffUsername.Value=plr.Name
wait(0.1)
game.ReplicatedStorage.Systems.CuffUsername.Value=" "
end
end)
end)
Before answering, I'd like to elaborate that this script does 100% work. It has been tested, but for some reason, this error keeps happening in this game.
Thanks in advance.

4 comments
just moved the humanoid variable inside the if statement
you were trying to find 'Humanoid' when the mouse clicks an object. If the object doesn't have humanoid, it will return the error you are having
add 'if m.Target' so when you click the sky it doesn't return a nil error
Didn't make a difference, thanks for trying though.