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

npc head that follows the players position , I tried making something but it does not work?

local block = script.Parent
local Player = game.Players.LocalPlayer
local HumPart = Player.Character:WaitForChild("HumanoidRootPart")

while true do
	block.Orientation.X =  HumPart.Orientation.X
	block.Orientation.Y =  HumPart.Orientation.Y
	block.Orientation.Z =  HumPart.Orientation.Z
	wait()
	end

2 answers

✓ Accepted answer

Setting the block's orientation to the player's HumanoidRootPart won't work the way you want it.

This should work:

local Block = script.Parent
local PlayerS = game:GetService("Players")
game:GetService("RunService").Heartbeat:Connect(function() --rather than using a while true do loop, I used heartbeat so there isn't as much lag
	FindClosePlayer() --function is called every frame 
end)
function FindClosePlayer()
	for _, player in pairs(PlayerS:GetPlayers()) do -- This is just a method of getting a player from a server script
		local Character = player.Character or player.CharacterAdded:Wait() --this just waits for the character (that is if the character hasn't loaded yet)
		local RootP = Character:WaitForChild("HumanoidRootPart")
		local Dis = (Block.Position-RootP.Position).magnitude
		if Dis <= 40 then --checks distance
			Block.CFrame = CFrame.new(Block.CFrame.Position,RootP.CFrame.Position) ---Using CFrame you can make the block look like it's facing the character
			else
		end
	end
end

It's a lot but it works nicely.

3 comments

0

Only thing is IT GOes beyond 90 degrees witch is REALLy weird for a head

0

btw his was a localscript yours is a script and if two or more players are withing distance it will work a bit weird

0

Its a single player game

if you give the block the same orientation as the player then it will look at the same thing as player not look at the player, this should generate a cframe with an orientation that looks at the player

put this in the while loop

block.CFrame = CFrame.new(block.Position,HumPart.Position)

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