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

Why wont the GUI update after the second change?

Asked by 4 years ago
Edited 4 years ago

Hello everyone, i have a basic script that doesnt seem to work, and i spent about 1 hour on it and still cant seem to figure it out, i have tried man methods, but all have failed.

Firstly, its a basic script, only 25 lines of code, the second script has about 5.

Here it is:


-- The Variables local Status = script.Stats local clock = 0 local ServerStorage = game:GetService("ServerStorage") local MapsFolder = ServerStorage:WaitForChild("Maps") -- INTERMISSION -- while true do clock = 15 -- How long the intermission lasts repeat clock = clock - 1 -- Take away 1 second from the time until it runs out Status.Value = "Intermission, please wait: "..clock.." Seconds Left!" -- The status value is updated, and the last part is = to the time on the clock wait(2) until clock == 0 Status.Value = "Choosing Map..." wait(3) Status.Value = "Almost Done!" local AvailableMaps = MapsFolder:GetChildren() -- Gets all the maps from Server Storage local ChosenMap = AvailableMaps[math.random(1, #AvailableMaps)] Status.Value = ChosenMap.Name.." Was Chosen! Starting Game..." -- This wont show up in the gui end

There is a gui, and a text label. The text label has a local script that goes as:

-- Sets the value of the text in the gui to the value of the Stats in Mainscript
script.Parent.Visible = true

while wait() do
    script.Parent.Text = workspace.MainScript.Stats.Value
end

So far, what happens is just what i wanted. A gui at the top of the screen says:

Intermission! Please Wait (number of seconds) left!

and then the gui says

Choosing Map

But for whatever reason, anytime i try to add any other simple line of code JUST like the ones before, it doesnt work.

For some reason, the Almost done gui doesnt show up, why is this? Any kind of Doesnt work, how can i fix this.

EDIT:

Im also not getting any errors when playing the game.

0
Where are you putting the code? If you put the code after the while loop it won't run since scripts run top to bottom and as long as the while loop is running, it won't reach the code under there. royaltoe 5144 — 4y
0
All the code you see there are the entire scripts. The first one is the first script, in workspace. And the second script is the one 6 lines of code, in the text label under screen gui in starter gui. SimplyBloo 27 — 4y

1 answer

Log in to vote
1
Answered by
Dfzoz 489 Moderation Voter
4 years ago
Edited 4 years ago

FIRST PARAGRAPH IS SOLUTION

You didnt put a wait() after the Status.Value changes to (ChosenMap.Name.." Was Chosen! Starting Game..."), so it restarts the loop and the text changes to ("Intermission, please wait: "..clock.." Seconds Left!") before you see the previous message. Adding a yield after line 22 will fix it.

These are just for performance improvements you might add to prevent future lag:

Try using events to change things constantly instead of loops, like on the local script you made. You can try:

-- Sets the value of the text in the gui to the value of the Stats in Mainscript
script.Parent.Visible = true

workspace.MainScript.Stats:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = workspace.MainScript.Stats.Value
end)

You can also use events to yield something if it is a yieldable function, like this:

-- Sets the value of the text in the gui to the value of the Stats in Mainscript
script.Parent.Visible = true
while true do
    workspace.MainScript.Stats:GetPropertyChangedSignal("Value"):Wait()
    script.Parent.Text = workspace.MainScript.Stats.Value
end

These are good for keeping performance and getting a faster response on your game. For example, when your game starts, you could add a loop to check how many players are "alive" or any other condition you want. That would create a check function for each player every second, which may not lag that much if its a simple code, but if you want to raycast, use region3 and more complex functions on a lot of objects frequently, you could, for example, add a character.Died or a map:ChildRemoved() to check if a player was eliminated. That reduces the check frequency by 300 times, depending on the amount of times the code loops on the match timer. You can keep a timer loop on the match and add a matchended bool value that checks player elimination with an event and turns true if only one is left, and make the loop check if the time reached 0 or matchended is true.

0
Thank you so much I completely understand now. SimplyBloo 27 — 4y
Ad

Answer this question