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.
FIRST PARAGRAPH IS SOLUTION
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.