Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to destory a part that has been named after the user's id?

I'm trying to figure out how to delete a part that has been named after the user's id. I'm currently using FindFirstChild to find the id, however I cannot find how to delete it/Destroy().

local player = game.Players.LocalPlayer.UserId -- localplayer's id
local playername = game.Players.LocalPlayer.Name -- localplayer's name
local car = game.ReplicatedStorage.Cars.PoliceCar -- location of car
local clonedcar = car:Clone()-- clones car

function SpawnCar()
	clonedcar.Name = player -- changes name of car to localplayer's id
	clonedcar.VehicleSeat.Owner.Name = playername -- changes the owner of the car to the player's name
	clonedcar.Parent = game.Workspace -- moves car to workspace
end -- everything above here works fine.

script.Parent.MouseButton1Click:connect(function() -- on button click
    if game.Workspace:FindFirstChild(player) == nil then -- if car doesn't exist then
        SpawnCar() -- spawn new car
    else
		-- stuck here.
    end
end)

1 answer

✓ Accepted answer

game.Workspace:WaitForChild(player,1):Destroy()

or

game.Workspace[playerDestroy()

This discussion is preserved as it was. New answers, comments, and votes are closed.