Okay so I have been trying to fix my script that removes a players clothing, hats and sets the body color to a color that the player selected in a GUI. I am having a issue with the script and I don't understand why this error is happening.
I have the script placed in StarterCharacterScripts which is a child of StarterPlayer and the script is a LocalScript.
Here is the script.
script.Parent:WaitForChild("Humanoid").Died:connect(function() wait(5) local character = script.Parent local children = character:GetChildren() local skin = game.Players.LocalPlayer.Information.Skin.Value if children:FindFirstChild("Shirt") then local a = children:FindFirstChild("Shirt") a:Destroy() end if children:FindFirstChild("Pants") then local b = children:FindFirstChild("Pants") b:Destroy() end if children.Head:FindFirstChild("face") then local c = children.Head:FindFirstChild("face") c:Destroy() end local d = children:FindFirstChild("Body Colors") d:Destroy() local e = game.ReplicatedStorage[skin]:FindFirstChild("Body Colors") local f = e:Clone() f.Parent = children for i = 1, #children do if (children[i].className == "Hat") then children[i]:Remove() end end end)
Sorry if this script is longer than it needs to be, it just helps me understand what is going on when I write it.
My previous script that I made and was using, it was working in studio but when a player died in game, it would set all player's body colors to the player that died. This was the next best thing I could think that would work but I guess I was wrong. All help will be greatly appreciated.
You're trying to call FindFirstChild on a table
For example, you have: children:FindFirstChild("Pants")
but children is equal to: character:GetChildren()
Instead, your code should be:
character:FindFirstChild("Pants")
Essentially, FindFirstChild is a method specific to objects on ROBLOX (models, parts, services, etc.). When you put :GetChildren() at the end of an object, you're getting a table, and FindFirstChild isn't compatible with tables.
This really doesn't fix the script, but; if you want to remove the character's clothing, hats, packages, and T-shirts , then under StarterPlayer > Character > LoadCharacterAppearance, you can uncheck this and they won't spawn with those.