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

[EDITED!] Colors not changing?

Why doesn't this work, no errors, colors just won't change. Simple script I was playing around with btw

--ORIGINAL SCRIPT
game:GetService("Players").PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
	wait(.5)
        for _,part in pairs(char:GetChildren()) do
            if part:IsA("BasePart") then -- CHANGED FROM PART TO BASEPART
                part.BrickColor = BrickColor.Random()
            end
        end
    end)
end)

[[EDITED]] / / / This still will not work, I am completely clueless

function newPlayer(player)
    local char = player.Character
	for _,part in next,char:GetChildren() do
        if part:IsA('BasePart') then
            part.BrickColor = BrickColor.Random()
        end
    end
end

game.Players.PlayerAdded:connect(newPlayer)

-- manually fire it for already joined players
for _, player in pairs(game.Players:GetPlayers()) do
    newPlayer(player)
end

3 comments

0

For people answering, might it be a Skin Colors property overriding the color of the actual brick parts?

0

Enable your script if its disabled

0

Script is enabled, M39 might be on to something

3 answers

✓ Accepted answer

Try this:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        for i,v in pairs(char:GetChildren()) do
            if part:IsA('BasePart') then
                part.BrickColor = BrickColor.Random()
            end
        end
    end)
end)

2 comments

0

It was working lol, I was using a local script, but thanks anyways!

0

Oh, why didn't you say you were using a LocalScript? There's an easy way to fix that lol. Just take out the last two ends and remove the PlayerAdded and CharacterAdded functions and add a local variable after game.Players.LocalPlayer:CharacterAdded:wait() and add char = game.Players.LocalPlayer.Character

I'm not completely sure this will help but instead of using Part as your ClassType use BasePart because BasePart covers wedges, trusses, and whatnot.

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		for _,part in next,char:GetChildren() do
			if part:IsA('BasePart') then
				part.BrickColor = BrickColor.Random()
			end
		end
	end)
end)

1 comment

0

Still doesn't work

Were you testing this using Test Solo?

There's a gotcha with PlayerAdded -- when testing with Test Solo, the player will usually join before any scripts run. As a result, no PlayerAdded event will be fired, because it was hit before the script started listening.

The fix is to write it like this:

function newPlayer(player)
	-- do whatever to player
end

game.Players.PlayerAdded:connect(newPlayer)

-- manually fire it for already joined players
for _, player in pairs(game.Players:GetPlayers()) do
	newPlayer(player)
end

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