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 Brick Turn Towards Nearest Player?

My attempt:

magnitude = (script.Parent - workspace.Player).magnitude

while true do
	if magnitude < 50 then
	wait()
script.Parent.CFrame = CFrame.new(script.Parent.Position, workspace.Player)
	end
end

1 answer

workspace.Player can only be used from Server test or put your name.

I put a wait because without this little "wait(3)" you'll got an error such as "Player, a nil value" or other things like that.

I also create a variable named "numberPrinted" and printting it for beign sure it work.

don't forgot to put a wait() in you're while because you'll crash if you're torso to the part is not in 0 to 49.

you also need to put your variable "magnitude" in the while because if the player move the value of magnitude will not change and for get the magnitude you need to put the two position and not the userdata(the part or the player)

your code fix here: enjoy ;)

wait(3)
local numberPrinted = 0
while true do
	magnitude = (script.Parent.Position - workspace.Player.Torso.Position).magnitude
	if magnitude < 50 then
		numberPrinted = numberPrinted + 1
		script.Parent.CFrame = CFrame.new(script.Parent.Position)
		print("same"..numberPrinted)
	end
	wait(0)
end

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