UDim2 Scripting Problem

  1. I want to achieve a for loop that will loop through every player and clone a text button for them

  2. The issue is that I don’t know how to make the UDim2 position change for every player

  1. I have tried multiplying another UDim2 value to add up when cloning for the next player but it just won’t work.
local players = game:GetService("Players")

local textbutton = game.ReplicatedStorage.TextButton

local position = UDim2.new(0, 0,0.13, 0)

wait(5)
for i, v in pairs(players:GetChildren()) do
	print("run")
	local tt = textbutton:Clone()
	tt.Parent = game.Workspace.Part.SurfaceGui.selectFrame
	tt.Position = UDim2.new(0, 0,0.13, 0)
	tt.Text = v.Name
end


1 Like

One way you could do this is to use the :FireAllClients() method using a remote event.

Then you can make the button appear using a local script by calling that remote using OnClientEvent. You won’t need the loop since it’ll activate the Remote Event for all players in the server at the time.

1 Like

I see but how would I know that the first player is already here and change the position of the textbutton??

I just found out about UIListlayout. I think it might work.

1 Like

I don’t think it’s possible to add something from ReplicatedStorage to a gui.

Just make the entire GUI and make things visible, invisible, etc.

Use UDim2 when tweening.

1 Like

don’t worry about that it is working. I was just trying to ask about how I would clone the textbuton when every player joins and have them in an order. I think I found a solution for the order.

Here’s an example.

People: there’s 5 people playing your game, woohoo.

Extra Notes: There’s a remote event in ReplicatedStorage called “Remote”.

--Script in ServerScriptService--
game.ReplicatedStorage.Remote:FireAllClients()

That’s really simplified, but it’s just an example.

--Now in a local script in StarterGui--
game.ReplicatedStorage.Remote.OnClientEvent:Connect(function()
     --Textbutton stuff here
end)
1 Like

That activates for all 5 people in your game.

yes but keep in mind this is a board. Will all people see everyone’s name’s on the board??

Depends on how it’s scripted. Otherwise, I recommend you study RemoteEvents more, they’re extremely useful.

1 Like

yes I already know about RemoteEvents thanks. I just don’t know about the suggestions. I feel like using a remoteEvent is not useful in this way because I want it server sided not client sided

Well, Guis are replicated from the server to the client so you could use a UIListLayout and clone/delete buttons you need to

kinda like

game.Players.PlayerAdded:Connect(function(player)
	for index, value in pairs(game.Players:GetPlayers()) do
		local Gui = value.PlayerGui
		local GuiButtonClone = --put gui button you need to clone here and :Clone() it
		GuiButtonClone.Name = player.Name
		GuiButtonClone = Gui.--screengui/frame you want it in
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	for i,v in pairs(game.Players:GetPlayers()) do
		local Gui = v.PlayerGui
		local Button = --put screengui here and :FindFirstChild(player.Name)
		if Button then Button:Destroy() end
	end
end)

edit:You should also make a function to clone everyone’s name thing to the player who joined, I forgot to do that but it shouldnt be too hard

1 Like

I think UiGridlayout does this automatically

1 Like

You can use a UIListLayout or UIGridLayout to automatically position the buttons! That’d be the best way to go for something like this!

1 Like