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

[EDITED!] Colors not changing?

Asked by 8 years ago

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
0
For people answering, might it be a Skin Colors property overriding the color of the actual brick parts? M39a9am3R 3210 — 8y
0
Enable your script if its disabled DigitalVeer 1473 — 8y
0
Script is enabled, M39 might be on to something dragonkeeper467 453 — 8y

3 answers

Log in to vote
-2
Answered by 8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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)

0
It was working lol, I was using a local script, but thanks anyways! dragonkeeper467 453 — 8y
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 lightpower26 399 — 8y
Ad
Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)
0
Still doesn't work dragonkeeper467 453 — 8y
Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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

Answer this question