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

Unable to cast double to Vector3?

Asked by 7 years ago

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)
0
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. M39a9am3R 3210 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

MoveTo() requires a Vector3 argument, you are giving it a double.

a^2 + b^2 + C^2 is a double, not a Vector3.

0
when you try so hard in formatting but you don't succeed User#15029 30 — 7y
Ad

Answer this question