So I'm trying to figure out how to spawn a car if the car the player does not have a car. While if the player does have already have a car, delete the existing car and replace the car. Here is the code that I am working with, thanks!
local player = game.Players.LocalPlayer.Name
local car = game.ReplicatedStorage.Cars.PoliceCar
local clonedcar = car:Clone()
function SpawnCar()
clonedcar.Name = player
clonedcar.Parent = game.Workspace
end -- everything above here works fine.
script.Parent.MouseButton1Click:connect(function()
if workspace:FindFirstChild(player) == nil then
SpawnCar() -- This doesn't work, only works if it is alone. It doesn't work with 'if'
else
print("Test") -- This is where I can't seem to figure out how to delete the player's car and spawn in a new one.
end
end)

2 comments
That doesn't work, it comes up with this 11:56:26.478 - Players.DJAppecer.PlayerGui.ScreenGui.TextButton.LocalScript:6: attempt to call upvalue 'player' (a string value) 11:56:26.479 - Stack Begin 11:56:26.480 - Script 'Players.DJAppecer.PlayerGui.ScreenGui.TextButton.LocalScript', Line 6 - global SpawnCar 11:56:26.481 - Script 'Players.DJAppecer.PlayerGui.ScreenGui.TextButton.LocalScript', Line 1
Fixed, I just made the car named after userid.