Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I change the rotation of this object to face the player?

Asked by 7 years ago

Alright, so I've got a part with a SurfaceGui that's locally made and positioned right in front of the player (2 studs in front of him) but it's facing away from the player, not towards the player. So, the player can't see the GUI.

local c = script.GUI:Clone()
c.Parent = game.Workspace.CurrentCamera
c.SurfaceGui.TextLabel.Text = "CREATED!"
repeat
    c.CFrame = game.Players.LocalPlayer.Character.Head.CFrame + game.Players.LocalPlayer.Character.Head.CFrame.lookVector * 2
    wait()
until (1 == 5) -- 1 will never be equal to 5, so :p

How can I change the rotation of the brick to face towards the player?

Thanks! :)

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago
local run = game:GetService('RunService')
local player = game.Players.LocalPlayer
local char = player.Character
local head = char:WaitForChild("Head")

run.RenderStepped:connect(function()
    -- Start at your head
    -- Rotate around 180 degrees
    -- Push away from your head 
    c.CFrame = head.CFrame * CFrame.Angles(0,math.rad(180),0) +  (head.CFrame.lookVector *2) 
end)
Ad

Answer this question