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

Why does this not work on a server?

I am trying to remove every shirt/pants/hats in a character and change the color of their body. Easy, but the problem is that it does not work. Here's the script:

local player = game.Players.LocalPlayer
local character = player.Character
repeat wait() until character
for i,v in pairs(character:GetChildren()) do
	if v:IsA("Hat") then
		v:Destroy()
		wait()
	end
	if v:IsA("Shirt") then
		v:Destroy()
		wait()
	end
	if v:IsA("Pants") then
		v:Destroy()
		wait()
	end
	if v:IsA("Part") then
		if v.Name == "Torso" then
			v.BrickColor = BrickColor.Black()
			wait()
		end
		if v.Name == "Left Arm" then
			v.BrickColor = BrickColor.Gray()
			wait()
		end
		if v.Name == "Right Arm" then
			v.BrickColor = BrickColor.Gray()
			wait()
		end
		if v.Name == "Right Leg" then
			v.BrickColor = BrickColor.Black()
			wait()
		end
		if v.Name == "Left Leg" then
			v.BrickColor = BrickColor.Black()
			wait()
		end
		if v.Name == "Head" then
			v.BrickColor = BrickColor.Gray()
			wait()
		end
	end
	
end

1 comment

0

In studio it works 1/2 of the time and on a server it does not work at all.

2 answers

✓ Accepted answer

The Character doesn't load with all of the clothing already set. It loads in a bit after. This script probably works before any of the character's appearance loads, which means the clothes are put on after this clear them.

If you want control over their appearance, just set player.CanLoadCharacterAppearance to false.

1 comment

0

Thanks.

Here...Try the script game.Workspace.ChildAdded:connect(function(obj) - if (obj:IsA("Hat")) then wait(4) if (obj.Parent == game.Workspace) then obj:Destroy() end end end) That will remove hats for your body color try this but remember to put it in your spawn location brick function onTouch(hit) local humanoid = hit.Parent.Humanoid if humanoid ~= nil then local head = hit.Parent.Head local torso = hit.Parent.Torso local leftleg = hit.Parent:findFirstChild("Left Leg") local rightleg = hit.Parent:findFirstChild("Right Leg") local rightarm = hit.Parent:findFirstChild("Right Arm") local leftarm = hit.Parent:findFirstChild("Left Arm") if head ~= nil then head.BrickColor = BrickColor.new("Bright yellow") if torso ~= nil then torso.BrickColor = BrickColor.new("Bright blue") if leftleg ~= nil then leftleg.BrickColor = BrickColor.new("Dark green") if rightarm ~= nil then rightarm.BrickColor = BrickColor.new("Bright yellow") if leftarm ~= nil then leftarm.BrickColor = BrickColor.new("Bright yellow") if rightleg ~= nil then rightleg.BrickColor = BrickColor.new("Dark green") end end end end end end end end script.Parent.Touched:connect(onTouch)

you can also put this in your spawn location block as a script to remove hats

function onTouched(hit) local d = hit.Parent:GetChildren() for i=1, #d do if (d[i].className == "Hat") then d[i]:remove() end end end

script.Parent.Touched:connect(onTouched)

1 comment

0
  1. Cant read anything 2. Already answered 3. I don't use spawn locations in the game ill make

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