Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does this not work on a server?

Asked by
Kyokamii 133
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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
0
In studio it works 1/2 of the time and on a server it does not work at all. Kyokamii 133 — 8y

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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.

0
Thanks. Kyokamii 133 — 8y
Ad
Log in to vote
0
Answered by
arez81 0
8 years ago

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)

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

Answer this question