I'm trying to create a Car Spawner, and it works fine. But I want the car to spawn infront of them.
This is my script that's causing an error:
RE.SpawnCar.OnServerEvent:Connect(function(player,carName) local spawnedCar = game:GetService("ReplicatedStorage"):WaitForChild("Vehicles"):FindFirstChild(carName):Clone() spawnedCar.Name = player.Name.."'s Car" spawnedCar.Parent = game:GetService("Workspace") spawnedCar:MakeJoints() local char = player.Character or player.CharacterAdded:Wait() spawnedCar:SetPrimaryPartCFrame(char.HumanoidRootPart.CFrame.LookVector + Vector3.new(0,3,10)) end)
And this is the error I am getting:
09:18:00.788 - Unable to cast Vector3 to CoordinateFrame
09:18:00.789 - Stack Begin
09:18:00.789 - Script 'ServerScriptService.EventHandler', Line 7
09:18:00.789 - Stack End
What you're trying to do is pass a Vector3 value into a function that takes a CFrame value. In order to solve your problem, all you need to do is to create a CFrame from the Vector3, which can be done by wrapping the Vector3 in CFrame.new().
spawnedCar:SetPrimaryPartCFrame(CFrame.new(char.HumanoidRootPart.CFrame.LookVector + Vector3.new(0,3,10)))
There's a really good answer on here about the difference between CFrame and Vector3, and I'd suggest for you to read it.