You can always try parenting the Gui itself to ReplicatedStorage and only cloning it to the PlayerGuis of those that matched the set requirements.
1 | local replicated = game:GetService( 'ReplicatedStorage' ) |
2 | local guiFile = 'SelectGun' |
3 | local players = game:GetService( 'Players' ) |
4 | local exempt = BrickColor.new( 'White' ) |
Edit exempt
to TeamColor
that should be exempt from distribution (above)
01 | players.PlayerAdded:connect( function (player) |
02 | local playerGui = player:WaitForChild( 'PlayerGui' ) |
03 | local clone = replicated:WaitForChild(guiName) |
05 | player.Changed:connect( function (property) |
06 | if property = = 'TeamColor' then |
07 | if ( not player [ property ] = = exempt) then |
08 | if ( not playerGui:FindFirstChild(guiFile)) then |
09 | clone:Clone().Parent = playerGui |
line 2 = finding or waiting for the player's PlayerGui
line 3 = finding or waiting for the pre-defined "gui" we want to clone
line 4 = fires when a property of player
is changed
line 5 = if the changed property is TeamColor
then go on
line 6 = if the TeamColor's set value does not equal the pre-defined exempt
TeamColor value then go on
line 7 = if the gui doesn't already exist in the player's PlayerGui then go on
line 8 = clone the pre-defined guiFile
done!