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

NPCS killing each other,i need help,anyone can help?

It's a Script located in a NPC. It's a part,not all the script. The point of this script,is verifying if the target is a player,but,it doesn't work.

wait(math.random(1,5))
    player = game:GetService("Players")
	local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
	if not target == player then
	if target ~= nil then
		script.Parent.Humanoid:MoveTo(target.Position, target)
	end
	end

1 answer

✓ Accepted answer

Hey there.

local players = game:GetService('Players')

wait(math.random(1,5))
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)

if target then
	--checking if it's a player
	local player = players:GetPlayerFromCharacter(target.Parent)
	
	if not player then -- if it's not a player
		-- do your stuff now
		script.Parent.Humanoid:MoveTo(target.Position, target)
	end
end


2 comments

2

Give a proper explanation.

0

You want to make sure that it's not a player, so the easiest way, is to check if there's a player for that character model(using game.Players:GetPlayerFromCharacter(), using "not" means that, if there's not a player for it, then do your stuff

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