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 9 years ago

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

01--ORIGINAL SCRIPT
02game:GetService("Players").PlayerAdded:connect(function(plr)
03    plr.CharacterAdded:connect(function(char)
04    wait(.5)
05        for _,part in pairs(char:GetChildren()) do
06            if part:IsA("BasePart") then -- CHANGED FROM PART TO BASEPART
07                part.BrickColor = BrickColor.Random()
08            end
09        end
10    end)
11end)

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

01function newPlayer(player)
02    local char = player.Character
03    for _,part in next,char:GetChildren() do
04        if part:IsA('BasePart') then
05            part.BrickColor = BrickColor.Random()
06        end
07    end
08end
09 
10game.Players.PlayerAdded:connect(newPlayer)
11 
12-- manually fire it for already joined players
13for _, player in pairs(game.Players:GetPlayers()) do
14    newPlayer(player)
15end
0
For people answering, might it be a Skin Colors property overriding the color of the actual brick parts? M39a9am3R 3210 — 9y
0
Enable your script if its disabled DigitalVeer 1473 — 9y
0
Script is enabled, M39 might be on to something dragonkeeper467 453 — 9y

3 answers

Log in to vote
-2
Answered by 9 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:

1game.Players.PlayerAdded:connect(function(plr)
2    plr.CharacterAdded:connect(function(char)
3        for i,v in pairs(char:GetChildren()) do
4            if part:IsA('BasePart') then
5                part.BrickColor = BrickColor.Random()
6            end
7        end
8    end)
9end)
0
It was working lol, I was using a local script, but thanks anyways! dragonkeeper467 453 — 9y
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 — 9y
Ad
Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 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.

1game.Players.PlayerAdded:connect(function(plr)
2    plr.CharacterAdded:connect(function(char)
3        for _,part in next,char:GetChildren() do
4            if part:IsA('BasePart') then
5                part.BrickColor = BrickColor.Random()
6            end
7        end
8    end)
9end)
0
Still doesn't work dragonkeeper467 453 — 9y
Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 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:

01function newPlayer(player)
02    -- do whatever to player
03end
04 
05game.Players.PlayerAdded:connect(newPlayer)
06 
07-- manually fire it for already joined players
08for _, player in pairs(game.Players:GetPlayers()) do
09    newPlayer(player)
10end

Answer this question