When a player presses e on their keyboard, they will be moved to the next nearest point on the wall, but this does not happen and i get the error Unable to cast double to Vector3
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local function FindNearestGrip()
local grips = game.Workspace:FindFirstChild("Grips", true):GetChildren()
table.sort(grips, function(a, b)
dstA = (a.Position - player.Character.HumanoidRootPart.Position).magnitude
dstB = (b.Position - player.Character.HumanoidRootPart.Position).magnitude
return dstA < dstB
end)
return grips[1]
end
mouse.KeyDown:connect(function(key)
if key == 'e' then
FindNearestGrip()
if dstA < dstB then
player.Character:MoveTo(dstB)
elseif dstB < dstA then
player.Character:MoveTo(dstA)
end
end
end)

1 comment
MoveTo requires a Vector3 value. You're getting magnitudes which is a^2 + b^2 + c^2 = m^2 which is a double value in the end.