Position bugged for my npc

  1. What do you want to achieve? Keep it simple and clear!
    Make the monster go behind the player
  2. What is the issue? Include screenshots / videos if possible!
    Monster does not go behind the player!!!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried putting the position as the negative lookvector i tried this before and it worked now it doesn’t anymore


local debounce = false
script.Event.Event:Connect(function()

	local nearestplr
	local maxrange = 100
	while task.wait(5) do
		if game.Workspace.Chasing.Value == true then


			if debounce == false then
				debounce = true
				for i,v in pairs(game.Players:GetPlayers()) do
					if v.Character and v.Character.Humanoid.Health > 0 then
						local magnitude = (v.Character.PrimaryPart.Position - game.Workspace.Fire.Position).Magnitude
						if magnitude <= maxrange then

							nearestplr = v.Character
						end
					end
				end
				kill(nearestplr)
			end
		else
			break
		end

	end
end)

function kill(nearest)
	if nearest and nearest.Humanoid.Health > 0 then
		print(nearest.Name)
		local Monster = game.ServerStorage.Monster:Clone()
		local part = Instance.new("Part")
		local plr = game.Players:GetPlayerFromCharacter(nearest)
		
		part.Parent = game.Workspace
		part.Position = plr.Character.PrimaryPart.CFrame.LookVector * 1
		print(tostring(plr.Character.HumanoidRootPart.CFrame.LookVector * 1))
		part.Anchored = true
		part.Name = "daniel"
		Monster.Parent = game.Workspace
		
		Monster.HumanoidRootPart.Smoke.Enabled = true
		nearest.Humanoid.WalkSpeed = 0

		Monster:MoveTo(part.Position) 
		task.wait(3)
		Monster.HumanoidRootPart.Smoke.Enabled = false
		task.wait(5)
		local anim = Monster.Humanoid:LoadAnimation(Monster.Animation)
		anim:Play()
		anim.Stopped:Wait()
		nearest.Humanoid.Health = 0
		Monster:Destroy()
		debounce = false	
	end

end
1 Like

Can you send footage of what happens?

1 Like

1 Like

Never mind use the video i accidently pasted the link

1 Like

The monster should be behind the player not outside the testing map

1 Like

Which section of the code calls the event? This may cause the problem, because if that event does not get called, nearest will be nil and “kill()” would never run

1 Like

it kills you though so that wouldn’t be the case

1 Like

Try teleporting the monster near the player, it might not move the monster because it is impossible for the monster to reach the player.

1 Like

it is teleporting though the monster is suppose to teleport behind the player play a animation and kill them

1 Like

Which part of the code teleports the monster?

1 Like

By teleport, I mean move the monster’s HumanoidRootPart a few studs away from the player (possibly 10 studs)

That part i also tried doing Monster.HumanoidRootPart.Position = part.position and it doesnt work

Where is the part anyways? in the video provided, there is no part

but in the code, there is a part created

Let me go to a baseplate to try and figure out a solution

the part is on the bottom of the feet of the monster which suppose to position itself behind the player

I think this code would work (It worked on my end)

local Part = script.Parent
local Rig = game.Workspace.Rig

Rig.HumanoidRootPart.CFrame = Part.CFrame - (Part.CFrame.LookVector.Unit * 10) + Vector3.new(0, 2.2, 0) – Adding the 2.2 studs higher ensures that the humanoidRootPart doesn’t sink through the ground

Edit: You will need to fix this code to fit yours, if you are having trouble with that, ask me and I will make a theoretically working version of your code

To make the monster move, you could do this:
Monster.Humanoid:MoveTo(part.Position) – Monster:MoveTo() made my Rig teleport to the player

Test it out and tell me if it works

part should be behind the plr so the monster can teleport right?

1 Like