lplayer = game.Players.LocalPlayer Players = game:GetService("Players") Head = lplayer.Character.Head bb = script.Parent bbt = bb.TextLabel function OnPlayerAdded(plr) bb.StudsOffset = Vector3.new(0,2,0) bbt.BackgroundTransparency = 1 bbt.Position = UDim2.new(0,0,.5,0) bbt.Font = "Legacy" bbt.FontSize = "Size18" bbt.TextWrapped = true bbt.TextColor3 = Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255) bbt.Text = plr.Name bb.Parent = Head end for _,v in pairs(Players:GetPlayers()) do OnPlayerAdded(v) end game.Players.PlayerAdded:connect(OnPlayerAdded)
Whenever I start a server with 2+ players it only gives it to 1 or none of the 2 players, any ideas on why that's happening?
**** EDIT ****
Players = game:GetService("Players") bbg = game.ReplicatedStorage.bbg -- Replace with correct path, of course function OnPlayerAdded(plr) plr.CharacterAdded:connect(function(character) repeat wait() until plr.Character and plr.Character.HumanoidRootPart local Head = plr.Character.Head if Head:FindFirstChild("bbg") then return else wait(1) local bb = bbg:Clone() local bbt = bb.TextLabel bb.StudsOffset = Vector3.new(0,2,0) bb.Size = UDim2.new(8,0,1,0) bbt.BackgroundTransparency = 1 bbt.Position = UDim2.new(0,0,.5,0) bbt.Font = "Legacy" bbt.FontSize = "Size18" bbt.TextWrapped = true bbt.TextColor3 = Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255) wait() bbt.Text = plr.Name bb.Parent = Head end end ) for _,v in pairs(Players:GetPlayers()) do wait() OnPlayerAdded(v) end end game.Players.PlayerAdded:connect(OnPlayerAdded)
This is happening because you're moving the billboardgui into the player, along with the script. There's only ever one instance of the billboardgui, so it will only give it to one player.
You could use :Clone() to make a new one each time:
lplayer = game.Players.LocalPlayer Players = game:GetService("Players") Head = lplayer.Character.Head bbg = script.Parent function OnPlayerAdded(plr) bb = bbg:Clone() bbt = bb.TextLabel bb.StudsOffset = Vector3.new(0,2,0) bbt.BackgroundTransparency = 1 bbt.Position = UDim2.new(0,0,.5,0) bbt.Font = "Legacy" bbt.FontSize = "Size18" bbt.TextWrapped = true bbt.TextColor3 = Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255) bbt.Text = plr.Name bb.Parent = Head end for _,v in pairs(Players:GetPlayers()) do OnPlayerAdded(v) end game.Players.PlayerAdded:connect(OnPlayerAdded)
EDIT: This should work fine, assuming it's a server script:
Players = game:GetService("Players") bbg = game.ReplicatedStorage.bbg -- Replace with correct path, of course function OnPlayerAdded(plr) repeat wait() until plr.Character local Head = plr.Character.Head bb = bbg:Clone() bbt = bb.TextLabel bb.StudsOffset = Vector3.new(0,2,0) bbt.BackgroundTransparency = 1 bbt.Position = UDim2.new(0,0,.5,0) bbt.Font = "Legacy" bbt.FontSize = "Size18" bbt.TextWrapped = true bbt.TextColor3 = Color3.new(math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255) bbt.Text = plr.Name bb.Parent = Head end for _,v in pairs(Players:GetPlayers()) do OnPlayerAdded(v) end game.Players.PlayerAdded:connect(OnPlayerAdded)