I’ve been having trouble with RemoteEvents recently, here’s a LocalScript I fixed up.
local rep = game:GetService("ReplicatedStorage")
rep:WaitForChild("DeliveryTravel").OnClientEvent:Connect(function()
local plr = game.Players.LocalPlayer
local node = workspace:FindFirstChild("DeliveryNodeFinish")
local char = plr.Character
local head = char:WaitForChild("Head")
local noti = rep:WaitForChild("Notify")
local gui = plr.PlayerGui.MainHUD.GPS
gui.Visible = true
repeat
local vector = (head.CFrame.Position - node.CFrame.Position).unit
local distance = (node.Position - head.Position).Magnitude
gui.Arrow.Rotation = vector.unit
gui.Distance.Text = math.floor(distance).. "m"
wait(0.08)
until distance < 1
gui.Visible = false
noti:FireServer(plr, "Mission completed.", 4)
end)
I’m trying to generate a direction vector and a Magnitude of the distance between the player’s head and a part. But, this error comes up in the output:
Attempt to index nil with "CFrame"
And these lines are the origin of the error:
local vector = (head.CFrame.Position - node.CFrame.Position).unit
local distance = (node.Position - head.Position).Magnitude
Any help is appreciated!