local function playerModifier(player)
local character = player.Character
if player.TeamColor == BrickColor.new("Navy blue") then
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpPower = 0
for i,v in pairs(character:GetChildren()) do
if v:IsA("Accessory") or v:IsA("Hat") then
v:Destroy()
print("ACCESSORY DESTROYED")
end
end
for _, character in pairs (character:GetChildren()) do
if character:IsA("BasePart") then
character.Transparency = 1
end
print("FINISHED.")
end
end
end
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
giveTools(plr)
playerModifier(plr)
end)
end)
The current issue is, the accessory part doesn’t destroy the player’s accessories when the join ingame and does not print out print("ACCESSORY DESTROYED") including errors, meaning there is something wrong with the code. I do not know what’s wrong with
for i,v in pairs(character:GetChildren()) do
if v:IsA("Accessory") or v:IsA("Hat") then
so I’m asking for help. I’d greatly appreciate the help received!
Maybe the player’s character hasn’t fully loaded yet, hence why it’s not destroying the players accessories. Try replacing local character = player.Character with local character = player.Character or player.CharacterAdded:Wait(). This might work.
I also tried player.CharacterAdded:Wait() but now one of the prints print("FINISHED.") doesn’t show up and the player’s avatar doesn’t completely disappear into Transparency = 1.
It’s challenging to fix because Roblox typically triggers the CharacterAdded signal when the character is loaded. In your case, the accessory isn’t loaded when you attempt to remove it.
The only solution I see is to insert a task.wait() before the loop to wait a short period for the accessory to load.
Additionally, try not to use the same name for the character variable and the value given in the second loop. I’ve renamed it to basePart to address this issue as well.
local function playerModifier(player)
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
if player.TeamColor == BrickColor.new("Navy blue") then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
task.wait()
local characterContent = character:GetChildren()
for i,v in pairs(characterContent) do
if v:IsA("Accessory") or v:IsA("Hat") then
v:Destroy()
print("ACCESSORY DESTROYED")
end
end
for _, basePart in pairs(characterContent) do
if basePart:IsA("BasePart") then
basePart.Transparency = 1
end
print("FINISHED.")
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
giveTools(plr)
playerModifier(plr)
end)
end)
If you have any questions, don"t hesitate to ask me!
When I copied and pasted the script, the accessories still didn’t get destroyed nor print out print("ACCESSORY DESTROYED"). While print("FINISHED.") does appear, the other one doesn’t. Is there something that has to do with
for i,v in pairs(characterContent) do
if v:IsA("Accessory") or v:IsA("Hat") then