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

What is wrong with this Changing Colors Script???

Asked by
IcyEvil 260 Moderation Voter
9 years ago

Im trying to make it change Players Character Models, Color Randomly all Parts(Except of course HumanoidRootPart)

Script:

while true do
    wait()
    for i,v in pairs(game.Players:GetChildren())do 
v.Character.Head.BrickColor = BrickColor.Random()
v.Character.LeftArm.BrickColor = BrickColor.Random()
v.Character.LeftLeg.BrickColor = BrickColor.Random()
v.Character.RightArm.BrickColor = BrickColor.Random()
v.Character.RightLeg.BrickColor = BrickColor.Random()
v.Character.Torso.BrickColor = BrickColor.Random()      
        end end

3 answers

Log in to vote
2
Answered by 9 years ago

The error in your script is that the wait time is too short. Also, there is a much more efficient way to accomplish what you want. Look at this:

while wait(0.1) do -- Infinite loop that runs every 0.1 second
    for _, v in pairs (game.Players:GetChildren()) do -- For each player we do
        for _, p in pairs (v.Character:GetChildren()) do -- For each instance of the current player we do
            if p:IsA("Part") and p.Name ~= "HumanoidRootPart" then -- Check if it's a part and not HumanoidRootPart
                p.BrickColor = BrickColor.Random() -- Change it's color
            end
        end
    end  
end
0
Thanks! IcyEvil 260 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

This is how I would do it....

while wait(1) do -- Use them at the same time, also add 1 secound!
    for _, v in pairs (game.Players:GetPlayers()) do -- Use GetPlayers() instead!
        local Char = v.Character
        if Char and Char:FindFirstChild('Torso') then -- Make sure they are there!
            Char.Torso.BrickColor = BrickColor.Random() -- Change the torso's BrickColor
            for _, item in pairs (Char.Torso:GetChildren()) do -- Use this to find joints...
                if item:IsA('Motor6D') and item.Part1 then -- Make sure its a joint, and that it is connected to something...
                    item.Part1.BrickColor = BrickColor.Random() -- Change the body part's color..
                end
            end
        end
    end
end

The unneeded code:

--[[
        v.Character.Head.BrickColor = BrickColor.Random()
        v.Character.LeftArm.BrickColor = BrickColor.Random()
        v.Character.LeftLeg.BrickColor = BrickColor.Random()
        v.Character.RightArm.BrickColor = BrickColor.Random()
        v.Character.RightLeg.BrickColor = BrickColor.Random()
        v.Character.Torso.BrickColor = BrickColor.Random()  
--]]
Log in to vote
0
Answered by 9 years ago
while wait(put time here) do
    for i, v in pairs(game.Players:GetChildren()) do
        v.Character.Head.BrickColor = BrickColor.new(math.random(1, 255)/255, math.random(1, 255)/255, math.random(1, 255)/255)
        v.Character.Torso.BrickColor = BrickColor.new(math.random(1, 255)/255, math.random(1, 255)/255, math.random(1, 255)/255)
        v.Character.RightArm.BrickColor = BrickColor.new(math.random(1, 255)/255, math.random(1, 255)/255, math.random(1, 255)/255)
        v.Character.RightLeg.BrickColor = BrickColor.new(math.random(1, 255)/255, math.random(1, 255)/255, math.random(1, 255)/255)
        v.Character.LeftArm.BrickColor = BrickColor.new(math.random(1, 255)/255, math.random(1, 255)/255, math.random(1, 255)/255)
        v.Character.LeftLeg.BrickColor = BrickColor.new(math.random(1, 255)/255, math.random(1, 255)/255, math.random(1, 255)/255)
    end
end

It might look wierd to you but it will work great. Each body part will have a different color every time the loop runs.

Answer this question