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

How to make a part point to a player?

I am trying to make a part that points to the player where ever they move, I have tried using, https://developer.roblox.com/en-us/articles/Understanding-CFrame, To get a better understanding of cframe. I have made a script but nothing comes up in the output, neither does the cube move, does anyone know how to answer this?

wait (2)
local cube = game.Workspace.Cube
local player = game.Players.LocalPlayer.Name


local targetPosition = player.HumanoidRootPart.Position


while true do
cube.CFrame = CFrame.new(cube.Position, targetPosition)

	end

3 comments

0

wait! i know! You are using "game.Players.LocalPlayer.Name" that gets the name of the player, this has no position, use "game.Players.LocalPlayer.Character"

0

sorry, the players name has no HumanoidRootPart inside it

0

Oh. Put that as an answer, I will accept it, if it works ofc.

1 answer

You got the right idea with the CFrame, but some of your other logic is off.

wait(2);
local cube = game:GetService("Workspace").Cube;
local plr = game:GetService("Players").LocalPlayer;

local targetPos;
while wait() do
	targetPos = Vector3.new(0,0,0);
	if plr.Character then
		targetPos = plr.Character.HumanoidRootPart.Position;
	end

	cube.CFrame = CFrame.new(cube.Position, targetPos);
end

1 comment

0

I'll say it only once: this code is redundant. "workspace" as a keyword almost entirely replaces every alternative and the while wait() do idiom is not being used correctly. Please stick to standard loops before you consider using idioms.

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