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

What is wrong with this Changing Colors Script???

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

✓ Accepted answer

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

1 comment

0

Thanks!

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()  
--]]
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.

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