Why doesn't this work, no errors, colors just won't change. Simple script I was playing around with btw
01 | --ORIGINAL SCRIPT |
02 | game: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 ) |
11 | end ) |
[[EDITED]] \/ \/ \/ This still will not work, I am completely clueless
01 | function 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 |
08 | end |
09 |
10 | game.Players.PlayerAdded:connect(newPlayer) |
11 |
12 | -- manually fire it for already joined players |
13 | for _, player in pairs (game.Players:GetPlayers()) do |
14 | newPlayer(player) |
15 | end |
Try this:
1 | game.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 ) |
9 | end ) |
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.
1 | game.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 ) |
9 | end ) |
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:
01 | function newPlayer(player) |
02 | -- do whatever to player |
03 | end |
04 |
05 | game.Players.PlayerAdded:connect(newPlayer) |
06 |
07 | -- manually fire it for already joined players |
08 | for _, player in pairs (game.Players:GetPlayers()) do |
09 | newPlayer(player) |
10 | end |