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

How do I see if a part exists by using a script?

Hello, In my script, I want to see if a different accessory is on my character, and if it is, I want it to destroy that accessory and add another. How do I do this?

Thank you, Kreativle

1 comment

0

if workspace:FindFirstChild("something") then workspace:FindFirstChild("something"):Destroy() end

1 answer

Try this.

local AccessoryName = "Accessory Name" --Put whatever the name of the accessory is in here


game.Players.PlayerAdded:Connect(function(Player) --Will do the function to the player that joins the game


	local AccessoryCheck = Player.Character:FindFirstChild(AccessoryName) --Will search the player's character model to see if they have the name of the accessory
	
	
	if AccessoryCheck then

		AccessoryCheck:Destroy() --Will delete the accessory from the game
	
	end
end

In the brackets is the name "Player". It is the variable which tells the game which player just joined.

1 comment

0

Player.Character will be nil, you need to wait for the characteradded event

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