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

Countdown GUI freezing?

I've ran into an annoying issue with my Countdown GUI. The script is supposed to count down how many seconds until a new minigame is chosen. However, the script stops working after it waits for 3 seconds. I did not run into this issue before I moved the script to a new place instance.

local MainBar = game.StarterGui:FindFirstChild("MainBar")
---------------
local MainBarFrame = MainBar:FindFirstChild("MainBarFrame")
---------------
local MainBarText = MainBarFrame:FindFirstChild("MainBarText")
---------------
local Minigames = game.ReplicatedStorage.Minigames:GetChildren()
---------------------------------------
MainBarText.Text = "Get ready for the next minigame!"
wait(3)
for i = 15,0,-1 do --How much time is left until the next minigame
MainBarText.Text = "Next minigame in " .. i .. " seconds!"
wait(1)
if i == 0 then
	MainBarText.Text = "Choosing a minigame..."
	Minigame = Minigames[math.random(1,#Minigames)]:Clone()
	Minigame.Parent = game.workspace 
	MainBarText.Text = "Minigame: " .. Minigame.MinigameName.Value .. " by " .. Minigame.MinigameCreator.Value .. "" 

This is what the Output told me: 16:40:55.368 - MainBar is not a valid member of PlayerGui 16:40:55.369 - Script 'Players.Player.PlayerGui.GameScript', Line 7 16:40:55.369 - Stack End

2 comments

0

Well, you're supposed to set MainBar to the Player's GUI. Although, by the error, it somehow seems you have. Is your game FIlteringEnabled?

0

There is no need for the 'if i == 0 then' if statement inside the for loop. Put it outside the for loop without the if statement. It will run right when the for loop finishes.

1 answer

✓ Accepted answer

I don get this glitch, but I fixed your script (it didn't work, anyway, so I made a new feature to change it for every player because StarterGui is like the StarterPack of GUIs):

local Minigames = game.ReplicatedStorage.Minigames:GetChildren()

function changeText(text)
	local p = game.Players:GetChildren()
	for i = 1,#p do
		local MainBar = p[i].PlayerGui:FindFirstChild("MainBar")
		local MainBarFrame = MainBar:FindFirstChild("MainBarFrame")
		local MainBarText = MainBarFrame:FindFirstChild("MainBarText")
		MainBarText.Text = text
	end
end

changeText("Get ready for the next minigame!")
wait(1)
for i = 0,15,1 do --How much time is left until the next minigame
	print(i)
	changeText("Next minigame in " .. 15 - i .. " seconds!")
	wait(1)
	if i == 15 then
	    changeText("Choosing a minigame...")
	    Minigame = Minigames[math.random(1,#Minigames)]:Clone()
	    Minigame.Parent = game.workspace 
	    changeText("Minigame: " .. Minigame.MinigameName.Value .. " by " .. 							Minigame.MinigameCreator.Value)
	end
end

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