-
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. -
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 -
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)