When a player clicks the gui when theres another player, the player spawns 2 cars even though the player clicked once. As soon as they spawn 2, because of the destroying system. They get spawned back to the spawn location.
What is meant to happen is it’s meant to only spawn 1 car for the player, not 2.
I don’t know why it keeps happening.
game.ReplicatedStorage.SpawnCar1.OnServerEvent:Connect(function(player)
print("Cloned")
local car = game.ServerStorage.Red:Clone()
car.Parent = game.Workspace
car:PivotTo(car.WorldPivot + Vector3.new(0,10,0))
car.Name = player.Name
local humanoid = player.Character:FindFirstChild("Humanoid")
local humanoidRoot = player.Character:FindFirstChild("HumanoidRootPart")
if car.Name == player.Name then
print("Got player car")
humanoid.Sit = false
humanoidRoot.CFrame = car.Seat.VehicleSeat.CFrame
car.Seat.VehicleSeat:Sit(humanoid)
script.Parent.Parent.Enabled = false
elseif not humanoid.VehicleSeat then
car.Seat.VehicleSeat:Sit(humanoid)
end
print(car.Seat.VehicleSeat.Occupant)
wait(3)
while wait(1) do
if car and car.Parent then
local occupant = car.Seat.VehicleSeat.Occupant
if occupant == nil then
car:Destroy()
humanoidRoot.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,1,0)
else
print("Car not found/ already deleted")
end
end
end
end)