Unable to cast double to Vector3

  1. What do you want to achieve?
    I want to get a car to spawn in varying locations using Parts named “SpawnPoint” each with their own different positions and names, I have inputed them into a table which later I can call a random "SpawnPoint’ Part and move the clonedCar to it.
  2. What is the issue?
    The issue is that the clonedCar cannot move to the part due to this error:
    Unable to cast double to Vector3 - Server - CarSpawnerScript:30
  3. What solutions have you tried so far?
    I have tried to add .Position to the end of the RandomTable instance in moveto but it had then came up with another error saying:
    attempt to index number with ‘Position’
    I have also tried making another local variable that equaled RandomTable.Position and usingthat variable in moveto but it yet again gave me:
    Unable to cast double to Vector3 - Server - CarSpawnerScript:30

I’m not sure what to do I have only started scripting a couple months ago!

Here’s my code

local ServerStorage = game:GetService("ServerStorage")
local PurchasedCars = game.ServerStorage:WaitForChild("PurchasedCars")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")
local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
local SpawnPoints = {
	game.Workspace.DealershipSpawnPoints.SpawnPoint,
	game.Workspace.DealershipSpawnPoints.SpawnPoint1,
	game.Workspace.DealershipSpawnPoints.SpawnPoint2,
	game.Workspace.DealershipSpawnPoints.SpawnPoint3,
	game.Workspace.DealershipSpawnPoints.SpawnPoint4
}

SpawnCarEvent.OnServerEvent:Connect(function(player, carName)
	local PlayerPurchasedCars = PurchasedCars:FindFirstChild(player.Name)
	if PlayerPurchasedCars then
		local Car = PlayerPurchasedCars:FindFirstChild(carName)
		local CurCar = game.Workspace:FindFirstChild(player.Name .. 'sCar')
		if CurCar then
			CurCar:Remove()
		end
		if Car then
			local clonedCar = Car:Clone()
			clonedCar.Name = player.Name .. 'sCar'
			if clonedCar:IsA("Model") then
				clonedCar:MakeJoints()
			end
			clonedCar.Parent = game.Workspace
			local RandomTable = (math.random(1,#SpawnPoints))
			clonedCar:MoveTo(RandomTable)
		end
	end
end)

DeleteCarEvent.OnServerEvent:Connect(function(player, Car)
	local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
	if Car then
		Car:Remove()
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
	if Car then
		Car:Remove()
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
		if Car then
			Car:Remove()
		end
	end)
end)

you are trying to move the humanoid to a number

local RandomTable = SpawnPoints[math.random(1, #SpawnPoints)].Position
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.