basicly what it does that it spawns the car and i need help to make it delete the car that is already spawned if i wanna spawn another one. my idea was that i do : game.Workspace.player.Name.."'s "..NameOfCar:remove but it didnt work.
Script: `game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 150000
cash.Parent = leaderstats
end)
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfCar)
return game.ServerStorage.Cars:FindFirstChild(NameOfCar).Price.Value
end
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player,NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
car:SetPrimaryPartCFrame(player.Character.Torso.CFrame + Vector3.new(-10,0,-10))
car.Parent = workspace
car:MakeJoints()
car.Name = player.Name.."'s "..NameOfCar
end)`
Try using find first child and then deleting it IF it exists:
local car = game.Workspace:FindFirstChild(player.Name.."Car") if car then car:Destroy() end