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

Help with a brick that follows you?

This script makes a part follow you. This script works fine but I want the part to be 10 studs above the chars head or torso. This script is in a part btw.

function onPlayerEntered(player)

player.CharacterAdded:connect(function(char)
while wait() do
	script.Parent.CFrame = CFrame.new(char.Torso.Position)
end
end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

✓ Accepted answer

What You Need To Do

In order for the part to be 10 studs above the character then you need to specify the point of origin, and the offset from that origin. Then set the part's CFrame to the origin's position, multiplied by the offset. In this case, the origin would be your character's Torso, and the offset would be CFrame.new(0,10,0).


Code

function onPlayerEntered(player)
	player.CharacterAdded:connect(function(char)
		while wait() do
			local origin = char:WaitForChild("Torso").CFrame
			local offset = CFrame.new(0,10,0)
			script.Parent.CFrame = origin * offset
		end
	end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

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