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

Why isn't this script locating Humanoid on some games?

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.

1 answer

✓ Accepted answer
script.Parent.Equipped:connect(function(m)
    m.Button2Down:connect(function()
        if m.Target.Humanoid then
		 local humanoid=m.Target.Humanoid -- please use tab to space ):
            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)

4 comments

0

just moved the humanoid variable inside the if statement

0

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

0

add 'if m.Target' so when you click the sky it doesn't return a nil error

0

Didn't make a difference, thanks for trying though.

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