Need help with my round system

I made a round system that teleports players and even has it own gui
The problem is I made a gui ready button and an integer value
When a player presses the button the integer value goes up by 1
I made an if statement to check if the integer value is 5 then it will run the round system script
but it doesn’t work at all I even tested it with 5 players all clicked the gui button but it still
doesn’t work please help
The integer value is called PlayersReady
Here is my code

local intermition = 30
local roundLength = 60
local inRound = game.ReplicatedStorage.InRound
local status = game.ReplicatedStorage.Status
local PlayersReady = game.ReplicatedStorage:WaitForChild("PlayersReady")
local TextButton = game:GetService("StarterGui").ReadyGui.Ready

if PlayersReady.Value == 5 then
	TextButton.Visible = false
	inRound.Changed:Connect(function()
		if inRound.Value == true then
			for i, player in pairs(game.Players:GetPlayers()) do
				local char = player.Character
				char:PivotTo(game.Workspace.GreenPart.CFrame)
			end
		else
			for i, player in pairs(game.Players:GetPlayers()) do
				local char = player.Character
				char:PivotTo(game.Workspace.SpawnLocation.CFrame)
				TextButton.Visible = true
				PlayersReady.Value = 0
			end
		end
	end)
	
	local function round()
		while true do
			inRound.Value = false
			for i = intermition, 0, -1 do
				status.Value = "Game will start in "..i.." seconds"
				wait(1)
			end
			inRound.Value = true
			for i = roundLength, 0, -1 do
				status.Value = "Game will end in "..i.." seconds"
				wait(1)
			end
		end
	end
	spawn(round)
end

Edit:
you are not checking it every time it changes you check it only once

you should use PlayersReady.Changed

Nope its entirely a server script.

Changed runs every time the value changes I don’t how to check if the value is 5

How can i use changed in this case?

1 Like
PlayersReady.Changed:Connect(function(value)
    if PlayersReady.Value == 5 then

    end
end)
1 Like

oh ok i will try that and see if it works

1 Like

Nope that didn’t work is there another way maybe?

1 Like

I see the strange thing here.

local TextButton = game:GetService("StarterGui").ReadyGui.Ready

it’s starter gui button and when you change starter gui that doen’t change every plr’s gui in server.
You should to change it for all players.
it changes gui only for those who died and respawned if your screen gui has ResetOnRespawn.
Try this.

for i,plr in ipairs(game:GetService("Players"):GetChildren()) do
    local plrgui = plr.PlayerGui
    local readygui = plrgui:WaitForChild("ReadyGui",10)
    local button = readygui.Ready
    button.Visible = false
end

So are you saying that I should fire a remote event to a new local script?

Nope, it’s not necessary.
You can just change gui of every player with this

Ok well where do i put this loop?

Where you set the button.Visible to false

I don’t understand?
What button?
I just putted it like this:

if PlayersReady.Value == 5 then
	TextButton.Visible = false
	for i,plr in ipairs(game:GetService("Players"):GetChildren()) do
		local plrgui = plr.PlayerGui
		local readygui = plrgui:WaitForChild("ReadyGui",10)
		local button = readygui.Ready
		button.Visible = false
	end
	inRound.Changed:Connect(function()
		if inRound.Value == true then
			for i, player in pairs(game.Players:GetPlayers()) do
				local char = player.Character
				char:PivotTo(game.Workspace.GreenPart.CFrame)
			end
		else
			for i, player in pairs(game.Players:GetPlayers()) do

delete this because if your screengui.ResetOnSpawn is true then everyone who reset after death can have this button invisible

Nope did not work I don’t know what else to do

I would advise you to check the value of this variable after every change with use print.
and add this

PlayersReady.Changed:Connect(function(value)
    if PlayersReady.Value == 5 then
        print(PlayersReady.Value,"Round is Starting")
    end
end)

Nope didn’t work i think its actually a problem with the gui I think guis don’t work in server script so i need to make a remote event to fire from server to client
And then make the gui from the client

No, better just add the local script in button.
with this

local button = script.Parent
button.MouseButton1Click:Connect(function()
    button.Visible = false
end)

or

local button = script.Parent
button.MouseButton1Click:Connect(function()
    if game.ReplicatedStorage:WaitForChild("PlayersReady").Value == 5 then
        button.Visible = false
    end
end)

When i press play in the main menu it makes button.visible = false so no need for that