my car gui spawner spawn multipe of the car help
``local player = game.Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar") local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar") local carName = script.Parent.Name local SpawnCarFrame = script.Parent.Parent
script.Parent.MouseButton1Down:Connect(function() SpawnCarFrame.Visible = false local CurrentCar = game.Workspace:FindFirstChild(player.Name .. 'sCar') if not CurrentCar then SpawnCarEvent:FireServer(carName) else if player.Character.Humanoid.SeatPart ~= nil and player.Character.Humanoid.SeatPart:IsA("VehicleSeat") then player.Character.Humanoid.Sit = false end wait() DeleteCarEvent:FireServer(CurrentCar) SpawnCarEvent:FireServer(carName) end end)
``local ServerStorage = game:GetService("ServerStorage") local ReplicatedStorage = game:GetService("ReplicatedStorage") local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar") local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
SpawnCarEvent.OnServerEvent:Connect(function(player, carName) local Car = ServerStorage:FindFirstChild("Cars"):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' clonedCar.Parent = game.Workspace clonedCar:MoveTo(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * 15) 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)
local CarSpawnerFrame = script.Parent.Parent.Frame
script.Parent.MouseButton1Down:Connect(function() CarSpawnerFrame.Visible = not CarSpawnerFrame.Visible end)
script.Parent.MouseEnter:Connect(function() script.Parent.ImageTransparency = 0 script.Parent.ImageColor3 = Color3.fromRGB(200,200,200) end) script.Parent.MouseLeave:Connect(function() script.Parent.ImageTransparency = 0.5 script.Parent.ImageColor3 = Color3.fromRGB(255,255,255) end)