Rotate object towards player client-side

  1. What I want to achieve? Make the parent of the local script rotate towards player (on clientside so for each player it rotates towards them)

  2. What is the issue? I can only make the part rotate towards player work if it isnt client-side

  3. What solutions have you tried so far? I tried using CFrame.lookAt, i searched the devforum but nothing worked yet :expressionless:

local Part  = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

while task.wait() do
	Part.CFrame = CFrame.lookAt(Part.Position, Character:GetPivot().Position)
end

heres the script i currently have

1 Like

try this.

local Part  = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CharRoot = Character:WaitForChild("HumanoidRootPart")

while task.wait() do
	Part.CFrame = CFrame.new(Part.Position, CharRoot .Position)
end
1 Like

I think you need to use a LocalScirpt as well so it only fires on the client. (I could be wrong though)

1 Like

i use localscript for it but it still doesnt work

But did you try @vitorpvp1337’s suggestion too?

First, add a Script into the part. Next, change the RunContext from Legacy to Client. Then, paste this script into the newly created script.

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local part = script.Parent
local player = Players.LocalPlayer
local playerCharacter = player.Character or player.CharacterAdded:Wait()

local runConnection = nil
runConnection = RunService.RenderStepped:Connect(function()
	if not playerCharacter then
		return runConnection:Disconnect()
	end
	
	part.CFrame = CFrame.lookAt(part.Position, playerCharacter:FindFirstChild("HumanoidRootPart").Position)
end)
1 Like

thank you so much dude it finally works :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.