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

How to change the rotation of a gui depending on a parts rotation?

A billboardgui is inside the player's character. Whenever the players touches a part, I want the billboardgui's imagelabel and the touched part to have the same rotation. How can this be done?

local RESET_SECONDS = 5
local isTouched = false  
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("IsPlayer") then
		if not isTouched then 
			isTouched = true
hit.Parent.HumanoidRootPart.Idle.idle.Rotation = script.Parent.Rotation
			print(script.Parent.Rotation)
			wait(RESET_SECONDS)  
			isTouched = false  
		end
	end
end)

1 answer

✓ Accepted answer

The result you desire to achieve doesn't really make sense. The rotation of a base part is expressed with 3 three angles used to rotate on 3 different axes, while the rotation of a GuiObject's rotation is expressed using a single angle that only rotates about one axis. This also causes a type mismatch.

What do you mean exactly when you want a GuiObject and a BasePart to have the same rotation? It could only mean that you want the rotation about a single axis on a plane of the BasePart and the GuiObject's to be the same, but which one exactly? X, Y, or Z?

For argument's sake, let's say you want the rotation about the Y axis of the part to be the same as the GuiObject's, where it rotates on the XZ plane. You can calculate the value by taking the arc tangent of the part's lookvector's X component and the Z component:

local look = script.Parent.CFrame.LookVector
local angle = math.atan2(look.x, -look.z)

hit.Parent.HumanoidRootPart.Idle.idle.Rotation = math.deg(angle)

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