I wanted to know if there was a better way to make a part face your mouse constantly other than:
Local Script
local player = game.Players.LocalPlayer; local mouse = player:GetMouse(); local rs = game:GetService('ReplicatedStorage'); local re = rs:FindFirstChild('RemoteEvent') or rs:WaitForChild('RemoteEvent'); local rf = rs:FindFirstChild('RemoteFunction') or rs:WaitForChild('RemoteFunction'); mouse.Button1Down:connect(function() re:FireServer() end) rf.OnClientInvoke = function() return mouse.Hit.p end
Script
local rs = game:GetService('ReplicatedStorage'); local re = rs:FindFirstChild('RemoteEvent') or rs:WaitForChild('RemoteEvent'); local rf = rs:FindFirstChild('RemoteFunction') or rs:WaitForChild('RemoteFunction'); re.OnServerEvent:connect(function(player) local part = Instance.new('Part', workspace); part.Anchored = true; part.CFrame = player.Character.Head.CFrame; while wait() do part.CFrame = CFrame.new(part.CFrame.p, rf:InvokeClient(player)); end end)
You can make the loop go faster by using the RunService.
while game:GetService("RunService").Heartbeat:wait() do part.CFrame = CFrame.new(part.CFrame.p, rf:InvokeClient(player)); end
Heartbeat:wait() is faster than wait() as it waits 1/30 of a second.
If you want it to smoothly transition, you can use lerp to smoothly transition between positions. Assuming you still want to update it quickly:
while game:GetService("RunService").Heartbeat:wait() do part.CFrame = part.CFrame:lerp(CFrame.new(part.CFrame.p, rf:InvokeClient(player)), .1); -- .1 controls its update speed. end