Hey. So there are quite a few things getting in the way here. The biggest problem is as soon as you start your game, the code skips through all the good stuff and goes straight to the while true do loop.
From that point on there is no way it will ever check if a GameValue changed because it is stuck in the while true do loop forever. So here’s what I did.
First of all I don’t know where you are storing your “GameValues” folder, so I set mine to game.Workspace.GameValues. Keep that in mind since if yours is in a different location you will need to change that in your script or it wont work.
First, make a new script in ServerScriptService and copy paste the following
local timerStopped = game.Workspace.GameValues.CounterStopped
wait(25)
timerStopped.Value = false
This is just to change the bool value you called “Stopped” after 25 seconds.
so your repeat until loop can recieve a new value.
now here is my version of your code. I added comments to hopefully help you understand what I did and why.
local CounterValue = 0
local GameValues = game.Workspace.GameValues --added
local Stopped = GameValues.CounterStopped -- changed stopped to the bool value that you named "CounterStopped"
CounterTime = GameValues.CounterTime -- added
function StartCounter(CounterValue) -- added parameter
for i = CounterValue, 0, -1 do
print(CounterValue)
task.wait(1) -- added so it counts down once every second
CounterValue = CounterValue - 1 -- added so the CounterValue actually changes each loop
if CounterValue == 0 then -- added so the for loop doesn't go into negatives
Stopped.Value = true
if Stopped.Value == true then
print("stopped")
repeat wait() until Stopped.Value == false
end
-- this line below wont print until the bool value "Stopped" = false, which we set up in the other script to happen after 25 second
print("Timer Stopped Value is False")
end
-- GameValues.CounterTime.Value = CounterValue -- commented out, because not needed
end
end
--[[ over here I took your ":Connect(function() line" and moved it below the StartCounter function, because we will need to pass the timers set time through the function, it will need to be done this way, especially if your different games have different times]]--
-- there is no need for a while true do loop because this function below is constantly checking for your CounterTime value to change
GameValues.CounterTime:GetPropertyChangedSignal("Value"):Connect(function()
CounterValue = CounterTime.Value -- took GameValues out of this line, no need since we declared it up top
StartCounter(CounterValue) -- added CounterValue parameter so we can run the time you set it to through the function
end)
wait(4)
CounterTime.Value = 10 -- notice how I changed the value through script, it wont work if you do it manually
--[[ -- not sure exactly how you want to incorporate this so i commented it out
function selectGame()
local GameSelected = math.random(1, #Games)
if table.find(GamesSelected, GameSelected) ~= nil then
repeat
GameSelected = math.random(1,#Games)
until table.find(GamesSelected, GameSelected) == nil
end
print(Games[GameSelected])
table.clear(GamesSelected)
table.insert(GamesSelected, GameSelected)
end
]]--
You can just copy paste the codes if you like but you’ll need to put your GameValues folder in Workspace. Otherwise make sure to change the location in your script.
I hope this helps to answer your questions. Anything else I can do to help let me know.
I’m fairly new to this too and helping others helps me to learn lots.