#How to make a part face you (client-sided)

1 messages · Page 1 of 1 (latest)

atomic tusk
#

I want to know how to make a script where a part faces towards you, just like how beams do (client-sided so each player sees the object facing them). Also I only want the part to rotate on the y-axis. Anyone know how to do this?

topaz solstice
dusty lilyBOT
#

studio** You are now Level 5! **studio

atomic tusk
#

how do I get the player's position?

topaz solstice
#

you could do LocalPlayer.Character.Head.Position

atomic tusk
#

LocalPlayer shows up with a red line underneath

topaz solstice
#

you will have to put this at the top

local Players=game:GetService("Players")
local LocalPlayer=Players.LocalPlayer

jagged yoke
topaz solstice
#

you also need to put the code thats making it face the player inside a loop so it will keep running

#

you can use RunService for that it you want it to be accurate every frame:
local RunService=game:GetService("RunService")
RunService.RenderStepped:Connect(function()
...
end)

or you can just do like
while task.wait() do
...
end

atomic tusk
#

I'm trying to do the RunService one and it isn't working

dusty lilyBOT
#

studio** You are now Level 1! **studio

atomic tusk
#

this is what I have in the localscript:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local RunService = game:GetService("RunService")

local _,ry = CFrame.lookAt(script.Parent.Position, LocalPlayer.Head.Position):ToOrientation()

RunService.RenderStepped:Connect(function()
script.Parent.Orientation = Vector3.new(0,ry*180/math.pi,0)
end)

topaz solstice
#

you need both these lines running every frame so that it knows which direction to look towards the player

RunService.RenderStepped:Connect(function()
local _,ry = CFrame.lookAt(script.Parent.Position, LocalPlayer.Head.Position):ToOrientation()
script.Parent.Orientation = Vector3.new(0,ry*180/math.pi,0)
end)

#

also if you're putting the script inside the part you want to rotate, make it a regular script

#

like this

#

and in properties change legacy to client

atomic tusk
#

ok

#

still isn't working

topaz solstice
#

can you send a screenshot of the code

#

or paste it

atomic tusk
topaz solstice
#

and are there any errors

#

change "LocalPlayer.Head"
to "LocalPlayer.Character.Head"

atomic tusk
#

it works!

#

thanks

jagged yoke
#

Needs spoonfeeding.

topaz solstice
#

you're welcome