Zombie = script.Parent Player = game.Players.LocalPlayer follow = false while true do if Player.Character.HumanoidRootPart ~= nil then if Player.Character.HumanoidRootPart.Position - Zombie.HumanoidRootPart.Position <= 10 then follow = true end end if follow then Zombie.Humanoid.WalkToPoint = Player.Character.HumanoidRootPart end wait(0.5) end
i get the error message "Line 6:Attempt to index global "Player" (a nil value)
It is nil because the script runs even if the player is not defined. Try this
Zombie = script.Parent Player = game.Players.LocalPlayer follow = false while true do if Player ~= nil then -- checks first if there is player if Player.Character.HumanoidRootPart ~= nil then if Player.Character.HumanoidRootPart.Position - Zombie.HumanoidRootPart.Position <= 10 then follow = true end end end if follow then Zombie.Humanoid.WalkToPoint = Player.Character.HumanoidRootPart end wait(0.5) end