Unable to create a new TextButton with players' names in the server

  1. What do you want to achieve?
    I would like to create a list of buttons, each one containing the username of a player in the server, and updating as new players join and leave.

  2. What is the issue?
    My script fails on the first line , according to print debugging.

  3. What solutions have you tried so far?
    I have tried creating a button without player names attached, it worked fine. The script is breaking from me trying to connect it to players for some reason.

game.Players.PlayerAdded:Connect(function(player)
		
			local button = Instance.new("TextButton")
			button.Parent = script.Parent.Menu
			button.Text = player.Name
			button.Name = player.Name
	
		print("worked")
end)

is this in a serverscript or localscript?

I created it as a server script, I didn’t make it local because I wasn’t sure how to grab other players names in a local script.

Put the Parent into PlayerGui

game.Players.PlayerAdded:Connect(function(player)
		
			local button = Instance.new("TextButton")
			button.Parent = player.PlayerGui.Menu
			button.Text = player.Name
			button.Name = player.Name
	
		print("worked")
end)

use a localscript like this:

game.Players.PlayerAdded:Connect(function()
		
			local button = Instance.new("TextButton")
			button.Parent = script.Parent.Menu
			button.Text = game.Players.LocalPlayer.Name
			button.Name = game.Players.LocalPlayer.Name
	
		print("worked")
end)
game.Players.PlayerAdded:Connect(function(player)

	local button = Instance.new("TextButton")
	button.Parent = player.PlayerGui.ScreenGui.IndexFrame2.ScrollingFrame.playerDrop.Menu
	button.Text = player.Name
	button.Name = player.Name
print("worked")
end)

put the parent into PlayerGui, “worked” never prints past the first line though, so same result ;-;

Alright,

So here is the LocalScript:

Put this into: StarterPlayerScripts

plr = game.Players.LocalPlayer

wait() -- Waits so there is a Player to add the TextFrame

button = Instance.new("TextButton") -- Change this if you like

button.Parent = plr.PlayerGui.Main
button.Size = UDim2.new(0,100,0,100) -- Sets to Default Size
button.Position = UDim2.new(0.5,0,0.5,0) -- Sets Position
button.Text = plr.Name
button.Name = plr.Name

	print("worked")


Edit: Thank you for my 49th Solution

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.