Hello, I want my car to clone after being clicked on the gui to a car spawn pad in the parking lot.
This is my current script how can I change it?
local plrCars = {}
game.ReplicatedStorage:WaitForChild("CarSpawnRE").OnServerEvent:Connect(function(plr, car)
if car then
if plrCars[plr] then
plrCars[plr]:Destroy()
end
local newCar = car:Clone()
local hrp = plr.Character.HumanoidRootPart
newCar:SetPrimaryPartCFrame(hrp.CFrame + (hrp.CFrame.LookVector * 10) + Vector3.new(0, 10, 0))
newCar.Parent = workspace
plrCars[plr] = newCar
end
end)
local plrCars = {}
local pad = workspace.Pad - CHANGE THIS
game.ReplicatedStorage:WaitForChild("CarSpawnRE").OnServerEvent:Connect(function(plr, car)
if car then
if plrCars[plr] then
plrCars[plr]:Destroy()
end
local newCar = car:Clone()
newCar:PivotTo(pad.CFrame + Vector3.new(0, 10, 0))
newCar.Parent = workspace
plrCars[plr] = newCar
end
end)
Just change the pad variable so it will be your parking lot.
Easy, Result is the random Parking Lot. (I guess the for i, v was unneccesary) (Yes it was)
local RandomParkingLot = math.random(1, #game.Workspace.Spawn.CarSpawnLocations:GetChildren())
local Result = game.Workspace.Spawn.CarSpawnLocations:GetChildren()[RandomParkingLot]
local plrCars = {}
local spawnLocations = workspace.AstralMap.Spawn.CarSpawnLocations
game.ReplicatedStorage:WaitForChild("CarSpawnRE").OnServerEvent:Connect(function(plr, car)
if car then
if plrCars[plr] then
plrCars[plr]:Destroy()
end
local randomLot = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren()) ]
local newCar = car:Clone()
newCar:PivotTo(randomLot.CFrame + Vector3.new(0, 10, 0))
newCar.Parent = workspace
plrCars[plr] = newCar
end
end)
local plrCars = {}
local spawnLocations = workspace.AstralMap.Spawn.CarSpawnLocations
game.ReplicatedStorage:WaitForChild("CarSpawnRE").OnServerEvent:Connect(function(plr, car)
if car then
if plrCars[plr] then
plrCars[plr]:Destroy()
end
local randomLot = spawnLocations:GetChildren()[math.random(1, #spawnLocations:GetChildren()) ]
local newCar = car:Clone()
newCar:PivotTo(randomLot.CFrame + Vector3.new(0, 10, 0))
local char = plr.Character or plr.CharacterAdded:Wait()
local _, carSize = newCar:GetBoundingBox()
char:PivotTo(newCar:GetPivot()*CFrame.new(carSize.X / 2 + 5, 0, 0))
newCar.Parent = workspace
plrCars[plr] = newCar
end
end)