You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
An interminable rooms E section eyeball that follows the nearest player.
What is the issue? Include screenshots / videos if possible!
I dont know how to code it.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Alot of posts.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
You can use either pathfindingservice or human:MoveTo() and do this in a while loop.
Get the targets(players) by doing this:
local function FindVictim()
for i, char in workspace:GetChildren() do
if char:FindFirstChildOfClass("Humanoid") then
local target = char
return target
end
end
end
not like that, like it looks at the player.
i have tried using cframe.lookat(), and failed.
an easier way to get the players is by just doing game.Players:GetPlayers()
lookAt is (not) deprecated and was (not) replaced with CFrame.new(pos,lookAt)
local part = script.Parent
local newPart = workspace.NewPart
part.CFrame = CFrame.new(part.Position,newPart.Position)
what this script does is make the 1stPart look at 2ndPart. Which is pretty much what you want.
Edit: lookAt isn’t deprecated and in fact is the replacement for CFrame.new(pos,lookAt) You should in fact be using LookAt Thanks to @Amritss for pointing this out
game["Run Service"].PreSimulation:Connect(function()
local MaxDistance = 1000000
local NearestPlayer = nil
for i, Player in game.Players:GetPlayers() do
if Player and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
if (Player.Character.HumanoidRootPart.Position.Magnitude - script.Parent.Position.Magnitude) <= MaxDistance then
NearestPlayer = Player
end
end
end
if NearestPlayer and NearestPlayer.Character and NearestPlayer.Character:FindFirstChild("HumanoidRootPart") then
script.Parent.CFrame = CFrame.new(script.Parent.Position,NearestPlayer.Character.HumanoidRootPart.Position)
script.Parent.Orientation += Vector3.new(180, 0, 180)
end
end)