Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this Billboard GUI work only for 1 person?

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)

1 answer

✓ Accepted answer

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)

6 comments

0

Also, you may want to put this in a server script, and put the billboardgui in one of the storages (and change line 7 to accommodate the change).

0

It still works with only 1 with 1 player, when you try a simulation with 2 players it doesn't really appear any billboard gui even when you added :Clone()

0

Did you follow my recommendation in the previous comment?

0

It displays for the players, but now when a player resets / dies it doens't show up more, should I set up a while true loop ?

0

After the Character dies it tells me this in the output "HumanoidRootPart is not a valid member of Model"

0

That's probably an issue with another script, as this script doesn't reference the HumanoidRootPart. And all you have to do is add a CharacterAdded event.

This discussion is preserved as it was. New answers, comments, and votes are closed.