For i, plrs in ipairs(players:GetChildren()) do only works for 1 player

Hello, Developers!

I’m trying to do an “Detect System” when a player clicks a UI button it copies an billboard gui with frame in it from workspace in to other players and only the player that clicked the UI button will see the billboard gui in other players. It does work but the billboard gui gets copied in to 1 player and not all the players as it should.

The script:

local players = game.Workspace.GameSystem.PlayersInGame.Survivor
local Button = script.Parent
local Used = false

Button.MouseButton1Click:Connect(function()
	if Used == false then
		for i, plrs in ipairs(players:GetChildren()) do
			if plrs.Name ~= game.Players.LocalPlayer.Name then
				Used = true
			local particles2 = Instance.new("BillboardGui")
			particles2.Size = UDim2.new(6,0,6,0) 
			particles2.AlwaysOnTop = true
			local particles = workspace.BillboardGui.ImageLabel:Clone()

			particles.Parent = particles2

			particles2.Parent = plrs.UpperTorso
			wait(10)
			particles2:Destroy()
			wait(120)
			Used = false
			end
		end
	end
end)

The reason it’s only one player is because you are using a local script

Because i want the billboard gui appear only for the player that clicked the button.

I guess it should be created when Used is false and, while this happens, it should turn true and when it finishes being false again, wait(120) and wait(10) delay the loop.

local players = workspace.GameSystem.PlayersInGame.Survivor
local Button = script.Parent
local Used = false

Button.MouseButton1Click:Connect(function()
	if Used == false then
		Used = true
		for i, plrs in ipairs(players:GetChildren()) do
			if plrs == game:GetService("Players").LocalPlayer then
				continue
			end
			
			local particles2 = Instance.new("BillboardGui")
			particles2.Size = UDim2.new(6,0,6,0) 
			particles2.AlwaysOnTop = true
			particles2.Parent = plrs.UpperTorso
			
			local particles = workspace.BillboardGui.ImageLabel:Clone()
			particles.Parent = particles2
			game:GetService("Debris"):AddItem(particles2, particles2)
		end
		task.wait(130)
		Used = false
	end
end)

Sources: task.wait, Debris:AddItem(), continue

3 Likes

Thank you so much, It worked but after 10 seconds all billboard guis should destroy, how do i do that? I tried customizing the script but then it didnt work.

Oops, should be

game:GetService("Debris"):AddItem(particles2, 10)

10 is the seconds it takes to be destroyed.

1 Like

Thank you so much! :slight_smile: I hope you have a good day!

1 Like

I will use this in the future. :slight_smile:

game:GetService("Debris"):AddItem(particles2, 10)

Debris:AddItem()'s second argument defaults to 10, just in case you weren’t aware.

I know, I just wrote it quickly, I corrected it below, if I didn’t know I wouldn’t have put the link to Debris:AddItem() without reading.

What I mean is that it doesn’t need to be explicitly passed.

Debris:AddItem(Instance, 10)
Debris:AddItem(Instance)
Achieves the same result.