Unable to cast double to Vector3

Hello, I ran into an issue a few hours back where when I try to move a model using MoveTo(Vector3.new). Here’s the 2 lines of code that I presume are causing this error (unable to cast double to vector3) to pop up.

monster:MoveTo(Vector3.new(-55.307, 8.072, -21.427))

and

monster:MoveTo(Vector3.new(-78.57, 7.267, -9.715))

If you need me to provide the rest of the code, please let me know. Thank you! -8ntlers

1 Like

All right, I have several solutions that may help you resolve this issue. Given the little information provided, I will assume all possible scenarios.

Solution I: (“monster” isn’t a model)
An easy fix it to group whatever “monster” consists of into a model. Keep in mind you cannot use :MoveTo() on objects that are a part.

Solution II: (“monster” is a file)
You cannot use files or configuration file instances to enact :MoveTo() on.

Solution III: (Incorrect formatting)
You may not have properly defined monster and could’ve set it to a variable such as an Int or String. I’d double check your definitions.

And if those don’t work here’s a reference API page: Model | Roblox Creator Documentation

2 Likes

These lines shouldn’t have errored. The error exerts when you only pass a double-type number to the MoveTo function. Could you provide the rest of the code?

4 Likes

I also did a little messing around in studio based on this. Are you sure there are no lines with :MoveTo(num1, num2, num3)? that will also error the same.

1 Like

Sure, here’s the rest of the code:

local fader = script.Parent.Parent.fade
local lever = game.Workspace["Lever Two Large Metal Pulls 3 (SFX)"]
local walk = game.Workspace["Walking Sounds Concrete Shoes"]
local flicker = game.Workspace["Lightbulb Flicker"]
local monster = game.Workspace["Cave Dweller"]
local lighton = game.Workspace["light power on 1"]
local sniff = game.Workspace.Sniff
local buzz = game.Workspace["Light Bulb Buzz 2 (SFX)"]
local step = game.Workspace.Loud_Step
local creak = game.Workspace["Wood Door Creak Squeak 2 (SFX)"]

task.wait(2.5)

local function typewrite(object,text,length)
	for i = 1,#text,1 do
		local sound = Instance.new("Sound")
		sound.Parent = game.Workspace
		sound.SoundId = "rbxassetid://9120300060"
		sound.Name = "DialogSound"
		sound:Play()
		object.Text = string.sub(text,1,i)
wait(length)		
	end
	for i,v in pairs(game.Workspace:GetChildren()) do
		if v.Name == "DialogSound" then
			v:Destroy()
		end
	end
end
buzz:Play()
typewrite(script.Parent, "Welcome to your new job.")
task.wait(4.5)
game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {TextTransparency = 1}):Play()
task.wait(1.5)
game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.2), {TextTransparency = 0}):Play()
typewrite(script.Parent, "Let's wait for your new friend to arrive.")
task.wait(3.5)
game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {TextTransparency = 1}):Play()
wait(0.5)
game:GetService("TweenService"):Create(fader, TweenInfo.new(1), {BackgroundTransparency = 1}):Play()
task.wait(1.5)
game:GetService("TweenService"):Create(fader, TweenInfo.new(0.2), {BackgroundTransparency = 0}):Play()
wait(1.2)

if fader.BackgroundTransparency == 0 then
	task.wait(2)
	creak:Play()
	wait(2)
	step:Play()
	wait(1.3)
	step:Play()
	wait(1.7)
	step:Play()
	wait(3)
	sniff:Play()
	wait(2)
	monster:MoveTo(Vector3.new(-55.307, 8.072, -21.427)) -- works
	script.Parent.TextTransparency = 0
	typewrite(script.Parent, "He's here...")
	task.wait(4.5) --line below this, make the texttransparency go from 0.1 to 1
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.2), {TextTransparency = 0.1}):Play()
	wait(1)
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {TextTransparency = 1}):Play()
	wait(0.6)
	game:GetService("TweenService"):Create(fader, TweenInfo.new(0.2), {BackgroundTransparency = 0}):Play()
	task.wait(1.5)
	game:GetService("TweenService"):Create(fader, TweenInfo.new(1), {BackgroundTransparency = 1}):Play()
	script.Parent.TextTransparency = 0
	wait(0.1)
	typewrite(script.Parent, "Don't be scared. He's friendly.")
	wait(4)
	script.Parent.TextTransparency = 0
	wait(0.1)
	typewrite(script.Parent, "You're armed, I assure you that-")
	wait(1)
	script.Parent.TextTransparency = 1
	flicker:Play()
	game.Workspace["Military Light"].Light.SpotLight.Enabled = false
	game.Workspace["Military Light"].Light.BrickColor = BrickColor.Black()
	buzz:pause()
	monster:PivotTo(CFrame.new(-55.307, 8.072, -21.427)) -- works -- try adding (number example) to each number
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {TextTransparency = 1}):Play()
	wait(1)
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.2), {TextTransparency = 0.1}):Play()
	wait(0.1)
	typewrite(script.Parent,  "....")
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.2), {TextTransparency = 0.1}):Play()
	wait(1)
	game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {TextTransparency = 1}):Play()
	walk:Play()
	wait(.8)
	lever:Play()
	wait(2)
	lighton:Play()
	game.Workspace["Military Light"].Light.SpotLight.Enabled = true
	game.Workspace["Military Light"].Light.BrickColor = BrickColor.White()
	buzz:Resume()
	script.Parent.TextTransparency = 0
	typewrite(script.Parent,  "Where'd he go...")
end


--(The code isn't finished yet)

A reason I think this is happening is because the Monster is a model, but a model with meshes, as I imported it from blender. If that is the case, how would I be able to move all of the meshes as a whole?
cavedweller

what do you mean with “works”? does that one works?

Try using

Vector2

and you should be good.

1 Like

Vector2 applies for 2D objects (UDim2 for UI), this is with 3D Positions, so we use Vector3 or CFrame

2 Likes

Ah. What’d you say he has to does then.

I mean, the code looks pretty fine to me.
It feels like this

Scratch that.

Try using that solution.

My grammar*

1 Like

Where does the output take you when you click on the error with your mouse?

1 Like

You should create a pseudo-humanoid that acts like a player with its meshes. Place your meshes under a model comprising the Humanoid object. You may need to weld your meshes later.

But the actual case is not the one you said above. The provided code does not have a statement that will error. Are you sure this is the right code snippet we are inspecting?

If you could not find the script, can you run the code below in your command bar and tell me what it prints?

for i, v in game:GetDescendants() do
	if v:IsA("LuaSourceContainer") then
		local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "Vector3%.new%(%d*%.?[%d]*%)")
		
		for i in findError do
			print(i, v:GetFullName())
		end
	end
end
1 Like

oh sorry, i added that before the issue and never noticed it. it does indeed not work.

For some reason, I don’t get the error anymore.

1 Like

It prints

  15:42:55.063  DataModel Loading https://assetdelivery.roblox.com/v1/asset/?id=12480846170  -  Studio
  15:43:00.989  > for i, v in game:GetDescendants() do
	if v:IsA("LuaSourceContainer") then
		local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "Vector3%.new%(%d*%.?[%d]*%)")
		
		for i in findError do
			print(i, v:GetFullName())
		end
	end
end  -  Studio
  15:43:00.998  Vector3.new() CoreGui.RobloxGui.Modules.Common.RagdollRigging  -  Edit
  15:43:01.015  Vector3.new() CoreGui.RobloxGui.Modules.InGameChat.BubbleChat.Components.BubbleChatBillboard  -  Edit
  15:43:01.064  Vector3.new() CoreGui.RobloxGui.Modules.ProximityPromptsTests.PlayerHelper  -  Edit
  15:43:01.076  Vector3.new() CoreGui.RobloxGui.Modules.Server.FreeCamera.FreeCamera (x4)  -  Edit
  15:43:01.097  Vector3.new() CoreGui.RobloxGui.Modules.VR.Panel3D

@ProBaturay

I still haven’t found a solution fyi

1 Like

The output says you’re fine with the MoveTo function. Are you still getting the error “Unable to cast double to Vector3” despite the output?

No, does that mean something or indicate why it’s not working?

1 Like

it says Unable to cast Vector3 to CoordinateFrame last time I tried, but I’ll try it again after I get out of this class

Just noticed, the line with the findError variable should be replaced with this line:

local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "MoveTo%(%d*%.?[%d]*%)")

The title refers to an error caused by passing a vanilla Lua type number to a Vector3 type expecting function. MoveTo function accepts Vector3, not a number. To avoid this issue, you have to find the line of code that is leading this error to occur. But the code samples you have provided previously do not consist of any error-emitting line. Therefore, I wrote a recursive function retrieving all of the scripts’ sources in your game in order to convey more info about the background of the error.

If you still encounter the error “Unable to cast double to Vector3” in your game and you assume there’s a nuisance with the MoveTo function, please replace the line I just revised with the one I gave you in my previous post, and you will have debugged your scripts.

for i, v in game:GetDescendants() do
	if v:IsA("LuaSourceContainer") then
		local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "MoveTo%(%d*%.?[%d]*%)")
		
		for i in findError do
			print(i, v:GetFullName())
		end
	end
end

Heres what it puts in the output –

 DataModel Loading https://assetdelivery.roblox.com/v1/asset/?id=12480846170  -  Studio
  14:46:10.023  > local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "MoveTo%(%d*%.?[%d]*%)")  -  Studio
  14:46:10.024  local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "MoveTo%(%d*%.?[%d]*%)"):1: attempt to index nil with 'Source'  -  Edit
  14:46:10.024  Stack Begin  -  Studio
  14:46:10.024  Script 'local findError = string.gmatch(string.gsub(v.Source, "%s", ""), "MoveTo%(%d*%.?[%d]*%)")', Line 1  -  Studio
  14:46:10.024  Stack End  -  Studio