I can't Modify Position

Hi my names Pixeluted and I want do NPC if player near then NPC run away but I want do Position But I got error

while wait() do
	local Players = game.Players:GetChildren()
	for _,player in pairs(Players) do
		local PlayerCharacter = workspace:FindFirstChild(player.Name)
		if PlayerCharacter then
			if (PlayerCharacter.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude <= 15 then
				local PositionMove = Vector3.new(PlayerCharacter.HumanoidRootPart.Position.X,PlayerCharacter.HumanoidRootPart.Position.Y,PlayerCharacter.HumanoidRootPart.Position.Z - Vector3.new(0,0,-6))
				print(PositionMove)
	
				
			end
		else
			print("Character Dont Founded")
		end
	end
end

Error Here
14:13:33.073 - Workspace.Dummy.Script:7: bad argument #1 to ‘?’ (Vector3 expected, got number)

14:13:33.074 - Stack Begin

14:13:33.074 - Script ‘Workspace.Dummy.Script’, Line 7

14:13:33.075 - Stack End

Thank for read

Change PositionMove to PlayerCharacter.HumanoidRootPart.Position - Vector3.new(0,0,6)

( That will teleport not make them run away )
Your mistake was not knowing that X,Y,Z are all numbers when extracted from a Vector3?

print(type(Vector3.new(0,0,1).Z))  -- will print number

Change this line:

local PositionMove = Vector3.new(PlayerCharacter.HumanoidRootPart.Position.X,PlayerCharacter.HumanoidRootPart.Position.Y,PlayerCharacter.HumanoidRootPart.Position.Z - Vector3.new(0,0,-6))

to this:

local PositionMove = PlayerCharacter.HumanoidRootPat.Position - Vector3.new(0,0,-6)
1 Like

Ok thats work but how to do NPC run when player be near ?

Try using Humanoid:MoveTo to make the NPC run and see if it works.

2 Likes

I think how to do position NPC be run because of player

Also, for future reference, please read the error more carefully to see that you gave it the wrong kind of value / data type (Z(number) - Vector when expected a number)
Also also, player.Character should be used instead.
I really don’t see the point in
Vector3.new(LONGX, LONGY, LONGZ-Vecto3…) anyway, just use
pos - Vector3.new(0,0,6) or something
Also try to use variables more so it is easier to read