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

Trouble with a script to find players in workspace and delete stuff?

for _, player in pairs(game.Workspace:WaitForChild():IsA("Model")) do
	if player.Humanoid and player.Animate and player.Health and player.Sound and player.Pants and player.Shirt and player["Body Colors"] then
		player["Body Colors"]:destroy()
		player.Shirt:destroy()
		player.Pants:destroy()
		player:WaitForChild():IsA("Hat"):destroy()
		player.Head.Color = BrickColor.new(Color3.fromRGB(255,255,255))
		player.Torso.Color = BrickColor.new(Color3.fromRGB(255,255,255))
		player["Left Arm"].BrickColor = BrickColor.new(Color3.fromRGB(255,255,255))
		player["Right Arm"].BrickColor  = BrickColor.new(Color3.fromRGB(255,255,255))
		player["Left Leg"].BrickColor = BrickColor.new(Color3.fromRGB(255,255,255))
		player["Right Leg"].BrickColor = BrickColor.new(Color3.fromRGB(255,255,255))
	end
end

"Argument 1 missing or nil"

"Stack Begin"

"Script 'Players.Player1.PlayerGui.CharacterCustomizerTest', Line 1"

"Stack End"

Does this mean I can't call for children in the workspace that are models?

1 answer

#What you did wrong :WaitForChild() only returns the object whose name is inside of the parenthesis. It returns an object, not a table like you're doing. Secondly, :IsA() turns the value into one of 2 values. True and False. So you're trying to get a player from the word true/false which will obviously error. You need the name of the part inside the parenthesis next to :WaitForChild() so it looks like so:

--Correct usages:
workspace:WaitForChild("Part") --Finds "Part" inside of workspace
print(workspace.Part:IsA("BasePart")) --The part is a basepart! So it's true!
--print's "true"
local table = {1,2,3,4,5,6,7}
for i,v in pairs(table) do end --note it's a table.

#Final Product

for _, player in pairs(game:GetService("Players"):GetPlayers()) do
    if player.Character:FindFirstChild("Humanoid") and player.Character:FindFirstChild("Animate") and player.Character:FindFirstChild("Health") and player.Character:FindFirstChild("Sound") then
--player.Character is used instead; :IsA() returns a bool value! not an object value!
--You need to study :WaitForChild() and :IsA() in the wiki ASAP!
        player:ClearCharacterAppearance() --Use this instead of "blah:Delete()" to delete hats and meshes
        for _,p in pairs(player.Character:GetChildren()) do
		if p:IsA("BasePart") then --Correct way of using ":IsA()"
			p.BrickColor = BrickColor.new(1,1,1) --When working with color3, the values are between 0 and 1.
		end
	end
    end
end


Hope it helps!

2 comments

0

Any way to make this work in studio and in-game so I can continue coding a future part?

0

Also, the reason why I used IsA() is because I heard it could search for a child with a specific class name. I didn't realize it only returned a bool value. Must be I do need to research further.

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