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

How do i make a part look in the direction of the player?

Asked by
Zzverot 16
5 years ago
Edited 5 years ago

So i'm trying to do 2 things here: First, i wanna make a part look at the player's head. I've put this in a local script

local part = script.Parent
game.Players.PlayerAdded:Wait()
local player = game.Players.LocalPlayer

part.ClickDetector.MouseClick:Connect(function()
    while wait(0.15) do
        part.CFrame = CFrame.new(part.Position, player.Character.Head.Position);
    end
end)

.

local part = script.Parent
game.Players.PlayerAdded:Wait()
local player = game.Players.LocalPlayer

while wait(0.15) do
    part.CFrame = CFrame.new(part.Position, player.Character.Head.Position);
end

I've tried both scripts but the part just stays the same when i run them.

Also, another thing is how can i make a part look at the pidection the player is facing? For example, if the player is looking towards positive Z,the part should also look towards positive Z. I've tried using part.CFrame.LookVector = character.Head.CFrame.LookVector (character and part are defined ofcourse) but it didn't work. Thanks is advance!

0
you cant define LookVector to something User#23365 30 — 5y
0
a localscript will not execute in workspace, so you either need to make this a localscript in a valid location for localscripts and change the part variable OR change LocalPlayer to an actual player & make it a serverscript instead Vulkarin 581 — 5y
0
The choice depends on whether you want the part to replicate it's movements or not Vulkarin 581 — 5y
0
Don't use wait() as your loop's condition; it abuses a hack. But I'd recommend doing it client sided as if you do this server sided, part movement can get really laggy. The movement should be processed on the client's end. User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
xEmmalyx 285 Moderation Voter
5 years ago

I didn't know of this either but with a bit of testing it appears LocalScripts can no longer move parts even client sided. I placed the same code into a regular script and it works perfectly fine

local part = script.Parent
game.Players.PlayerAdded:Wait()
local player = game.Players.xEmmalyx
player.CharacterAdded:Wait()

while wait(0.15) do
    part.CFrame = CFrame.new(part.Position, player.Character.Head.Position)
end

My username is xEmmalyx so of course you'd replace that with a player or use a script to find the nearest player.

Ad

Answer this question