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

[Solved] How to check if Tool.Parent is a player or no ?

I'm making a gun and i want that when a npc equip it with the Humanoid:EquipTool() it print(Gun.Parent.Name.." is a bot!") and if it's a player it does nothing so i tried this :

if not game.Players:GetPlayerFromCharacter(Gun.Parent) then
	print(Gun.Parent.Name.." is a bot!")
end

Sorry for my bad english.

3 comments

0

Check if the Humanoid's character name and check it if whether it's one of 'game.Players' , ;)

0

check the*

0

No, ew. They can just put a part with the same name as the player and put it in Players.

1 answer

✓ Accepted answer

local script, inside the gun

local gun = script.Parent --locating gun
local backpack = gun.Parent --locating the backpack

gun.Equipped:Connect(function()
if not backpack then
	print("a bot has equipped the tool") 
else
	print("a plr has equipped the tool")
end
end)

I am not sure but I assume NPCs do not have backpacks, if they do the case changes. Then you will need to do this.

Insert a bool into every single npc called "npc". The bool can be false or no doesn't matter.

After you have done that just add a local script inside the gun and write this there:

local gun = script.Parent --locating gun
local backpack = gun.Parent --locating the backpack
local plrornpc = backpack.Parent

gun.Equipped:Connect(function()
if plrornpc:FindFirstChild("npc") then
	print("a bot has equipped the tool") 
else
	print("a plr has equipped the tool")
end
end)

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