The script I have is to destroy all the clothes and t-shirt as well as change a player's skin color.
The script breaks at Line 4 giving the error: attempt to index global 'char' (a nil value)
I don't understand why it works in Studio but not in actual gameplay.
Here is the code.
local char = game.Players.LocalPlayer.Character
while wait(1) do
for i,v in pairs (char:GetChildren()) do
if v:IsA("Shirt") or v:IsA("CharacterMesh") or v:IsA("Pants")or v:IsA("ShirtGraphic") or v:IsA("Hat") then
v:Destroy()
end
if v.Name == "Torso" then
for _, TorsoChild in pairs(v:GetChildren()) do
if TorsoChild:IsA('Decal')then
print("Decal Removed")
TorsoChild:Destroy()
game.Players.LocalPlayer.Character.Head.BrickColor = BrickColor.new("Light orange")
game.Players.LocalPlayer.Character.Torso.BrickColor = BrickColor.new("Institutional white")
game.Players.LocalPlayer.Character["Left Arm"].BrickColor = BrickColor.new("Light orange")
game.Players.LocalPlayer.Character["Right Arm"].BrickColor = BrickColor.new("Light orange")
game.Players.LocalPlayer.Character["Left Leg"].BrickColor = BrickColor.new("Dark stone grey")
game.Players.LocalPlayer.Character["Right Leg"].BrickColor = BrickColor.new("Dark stone grey")
break
end
end
end
end
end

2 comments
Yes, this is in a LocalScript and also in the Player's PlayerGui
You should tab your code properly.