Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Zottic 19
5 years ago
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)
0
This is not specific what do you want the textbox to do? voidofdeathfire 148 — 5y
0
are you going to accept an answer? Imperialy 149 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
doesnt work Imperialy 149 — 5y
0
I did a new fix, hopefully it works, however it'll make TextBox.Text "60" Cvieyra2test 176 — 5y
0
Boom, done! Cvieyra2test 176 — 5y
Ad
Log in to vote
0
Answered by
Imperialy 149
5 years ago

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
0
But that loop just keeps going on which could cause lag. Cvieyra2test 176 — 5y
0
what.. no Imperialy 149 — 5y
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. Cvieyra2test 176 — 5y
0
if he changes iscounting to false in another function it breaks it Imperialy 149 — 5y
View all comments (2 more)
0
then how does iscounting turn to false Zottic 19 — 5y
0
in a whole new function Imperialy 149 — 5y

Answer this question