Model isn't moving too the correct location?

Hello, I have a system setup that teleports a model to a pad based on a random number generated between 1 and 6.

	if team == "Civilian" then
	local confirmedTeam = Teams:WaitForChild("Civilian")		
	if player.Team == confirmedTeam then
		local pad = math.random(1,6)
		local confirmedPad = game.ServerStorage.civCarSpawnPoints:FindFirstChild(pad)
		print(pad)
		
		local findCar = game.ServerStorage.cars:FindFirstChild(car)
		local confirmedCar = findCar:Clone()
		confirmedCar:MoveTo(confirmedPad.Position)
		confirmedCar.Name = player.Name.."'s Car"
		confirmedCar.Parent = insertedCars			
	else
		print("Not authed!")
	end
end	

This above code is supposed to find the model of the car, clone it, take it to the position oft the pad that was randomly selected and then set its parent to the workspace so it can be seen and used.

All this works apart from moving the model. It appears, but not at the location of the pad. I have confirmed this by printing the random number out and that ‘pad’ is not occupied by it.

Does anyone know why?
Thank you for your help…

The code for the most part looks correct, are you getting any error outputs in the console when the code is run?

Also, have you set the PrimaryPart of the model as well? Make sure to set the PrimaryPart of the model to a proper basepart of the car model, so that it could properly move it to its position. Do note that any MoveTo() functions require a Vector3 position for its parameter, and it will commit these calculations based on the PrimaryPart of the model.

1 Like

I am pretty sure the :MoveTo() function considers the surround parts of the workspace. That said, I would recommend using CFrame, and the function :SetPrimaryPartCFrame(). Simply create a part at the center of the model, make it completely transparent, and set the PrimaryPart of the model to that part. In your script, you will want to change it from:

confirmedCar:MoveTo(confirmedPad.Position)

To:

confirmedCar:SetPrimaryPartCFrame(CFrame.new(confirmedPad.Position))

Edit: If you want the car at a specific orientation, change it from CFrame.new(confirmedPad.Position) to confirmedPad.CFrame. Furthermore, adjust the primary part’s orientation to make it look the best as you intend.

1 Like