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

Why won't the TextBox change it's Text?

local StarterGui = game:GetService("StarterGui")
local TextBox = StarterGui.ScreenGui.TextBox

game.Players.PlayerAdded:Connect(function(player)
	
for i = 1,60,1 do
	TextBox.Text = i
	wait(0.1) break
end
end)

2 comments

0

This is not specific what do you want the textbox to do?

0

are you going to accept an answer?

2 answers

It's actually a quick fix, I've done the same issue myself in one of my own loops. (This assumes the script is in the workspace)

local StarterGui = game:GetService("StarterGui")
local TextBox = StarterGui.ScreenGui.TextBox

game.Players.PlayerAdded:Connect(function(player)

for i = 1,60,1 do
    TextBox.Text = i
    wait(0.1) break
end
end)

You have a "break" after the "wait(0.1)" which ends the loop right away after the first iteration, just remove it like this:

local StarterGui = game:GetService("StarterGui")
local TextBox = StarterGui.ScreenGui.TextBox

game.Players.PlayerAdded:Connect(function(player)

for i = 1,60,1 do
    TextBox.Text = i
    wait(0.1)
end
end)

That should do the fix, I didn't fully check the script for any other issues. (Before my relook)

Now after a relook, there's also another issue that other users were talking about in the comments, it doesn't update for other players. I also have a QUICK fix for that!

local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local TextBox = StarterGui.ScreenGui.TextBox

game.Players.PlayerAdded:Connect(function(player)

for i = 1,60,1 do
	for i,plr in pairs(Players:GetPlayers()) do
		local TextBox = plr.PlayerGui.ScreenGui.TextBox
		if TextBox then
			TextBox.Text = i
		end
	end
	wait(0.1)
end
end)

And to add to it, I think you're trying to get the amount of players, that is really easy to get!

game.Players.PlayerAdded:Connect(function(player)
	playercount = #game.Players:GetPlayers()
	for i,plr in pairs(game.Players:GetPlayers()) do
		local TextBox = plr.PlayerGui.ScreenGui.TextBox
		if TextBox then
			TextBox.Text = i
		end
		wait(0.1)
	end
end)

Sorry my answer is all over the place, but that last one should work!

3 comments

0

doesnt work

0

I did a new fix, hopefully it works, however it'll make TextBox.Text "60"

0

Boom, done!

You can't use a playeradded event inside of a gui or edit the startergui. Use a localscript inside of the textlabel with the following text

local TextBox = script.Parent
local iscounting = true
while iscounting do
	wait(1)
	if TextBox.Text ~= 0 then
		TextBox.Text = TextBox.Text - 1
	end
end

6 comments

0

But that loop just keeps going on which could cause lag.

0

what.. no

0

Well, it probably won't cause lag due to the wait(1), but the loop will still keep going because you haven't made 'iscounting' false during the loop.

0

if he changes iscounting to false in another function it breaks it

0

then how does iscounting turn to false

0

in a whole new function

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