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
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)
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)
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