Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to cast double to Vector3?

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

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.

1 answer

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

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

1 comment

0

when you try so hard in formatting but you don't succeed

This discussion is preserved as it was. New answers, comments, and votes are closed.