So the goal of this individual script is to wipe the player model of all shirts, pants, hats, and accessories on respawn and color the character to the color “Fossil” all around except for the torso (currently using R6) which will be colored the player’s team color.
Everything seems to work fine except for the fact that the player’s body parts won’t color the way I want it to. Oddly enough, however, the only part that does color correctly is the HumanoidRootPart.
There are no errors in the output.
There is a “Something unexpectedly set ___ parent to NULL” warning that I’m not sure how to remedy although it doesn’t seem to cause any problems while testing.
Specific Code:
local function wipePlayerModel(character)
local player = playersService:GetPlayerFromCharacter(character)
local headPart = character:FindFirstChild("Head")
local torsoPart = character:FindFirstChild("Torso")
for index, obj in pairs(character:GetChildren()) do
if obj and obj:IsA("Accessory") or obj:IsA("Hat") or obj:IsA("Shirt") or obj:IsA("Pants") then
obj:Destroy()
end
end
for index, bodyPart in pairs(character:GetChildren()) do
if bodyPart and bodyPart:IsA("BasePart") then
bodyPart.BrickColor = BrickColor.new("Fossil")
end
end
if headPart then
local face = headPart:FindFirstChild("face")
if face then
face:Destroy()
end
end
if torsoPart then
torsoPart.BrickColor = player.TeamColor
end
end
Entirety of Code:
local runService = game:GetService("RunService")
local playerService = game:GetService("Players")
local scriptService = game:GetService("ServerScriptService")
local server = scriptService:WaitForChild("server")
local settingsList = require(server:WaitForChild("Settings"))
local playersService = game:GetService("Players")
local shortcuts = require(script:WaitForChild("Shortcuts"))
local function wipePlayerModel(character)
local player = playersService:GetPlayerFromCharacter(character)
local headPart = character:FindFirstChild("Head")
local torsoPart = character:FindFirstChild("Torso")
for index, obj in pairs(character:GetChildren()) do
if obj and obj:IsA("Accessory") or obj:IsA("Hat") or obj:IsA("Shirt") or obj:IsA("Pants") then
obj:Destroy()
end
end
for index, bodyPart in pairs(character:GetChildren()) do
if bodyPart and bodyPart:IsA("BasePart") then
bodyPart.BrickColor = BrickColor.new("Fossil")
end
end
if headPart then
local face = headPart:FindFirstChild("face")
if face then
face:Destroy()
end
end
if torsoPart then
torsoPart.BrickColor = player.TeamColor
end
end
local function wipePlayerModelUsingChild(child)
if child and child.Parent:FindFirstChild("Humanoid") then
wipePlayerModel(child.Parent)
end
end
local function respawned(character)
runService.Stepped:wait()
wipePlayerModel(character)
character.ChildAdded:connect(wipePlayerModelUsingChild)
end
local function joined(player)
local character = player.Character or player.CharacterAdded:wait()
local leaderstats = shortcuts:CreateIntValue("leaderstats", 0, player)
shortcuts:CreateIntValue("KO", 0, leaderstats)
shortcuts:CreateIntValue("DMG", 0, leaderstats)
shortcuts:CreateIntValue("OBJ", 0, leaderstats)
player.CharacterAdded:connect(respawned)
if character then
respawned(character)
end
end
for num, player in pairs(playersService:GetPlayers()) do
joined(player)
end
playersService.PlayerAdded:connect(joined)