Problems with a player counter script

I’m attempting to make a countdown system which will trigger once at least 8 players have joined the queue, when a players clicks on the “Play” button it should count add 1 player to the count and remove it if the player leaves the game or clicks the “Back” button, the problem is that it will only count the player that triggered the count, for example, if I control 2 players and I make both of them join the queue the count will change display a 1 for both players when it is supposed to display a 2.

I haven’t tried anything yet except for making the script print after every single command, the result i got had something curious, there was a “A player has joined the queue” message printed once for each player on their own output, however the server’s output was empty. I haven’t tried anything else since I don’t really know where the error is.

This is the local script in charge of counting if a player joined the queue, it should be located inside every player’s play button.

local mouse = game.Players.LocalPlayer:GetMouse()
local sound = game.Workspace.Sound
local frame = script.Parent
local players = game.Workspace.Players
local teams = game:GetService("Teams")

function hover()
	script.Parent.TextLabel.TextXAlignment = ("Center")
	script.Parent.ImageButton.Size = UDim2.new(0.753, 0, 0, 0)
	sound:Play()
end

function unhover()
	script.Parent.TextLabel.TextXAlignment = ("Left")
	script.Parent.ImageButton.Size = UDim2.new(0.461, 0, 0, 0)
end

function less()
	print("A player has left the queue")
	players.Value = players.Value - 1
end

function more()
	print("A player has joined the queue")
	players.Value = players.Value + 1
end

function click()
	if players.Value < 15 then
	script.Parent.Parent.Info.Active = false
	script.Parent.Parent.Info.Visible = false
	script.Parent.Parent.Shop.Active = false
	script.Parent.Parent.Shop.Visible = false
	script.Parent.Parent.Play.Active = false
	script.Parent.Parent.Play.Visible = false
	script.Parent.Parent.Exit.Active = true
	script.Parent.Parent.Exit.Visible = true
	script.Parent.Parent.PlayMenu.Active = true
	script.Parent.Parent.PlayMenu.Visible = true
	game.Players.LocalPlayer.TeamColor = BrickColor.new("Shamrock")
	script.Parent.Parent.Title.Text = ("PLAY")
	end
	end
teams.Queued.PlayerRemoved:Connect(less)
teams.Queued.PlayerAdded:Connect(more)
frame.MouseEnter:Connect(hover)
frame.MouseLeave:Connect(unhover)
frame.MouseButton1Click:Connect(click)

This is my second post on these forums so if I committed any kind of mistake let me know, thanks beforehand :smiley:.

2 Likes

Hmph, it looks like you’re on the right track, though this code you provided is very limited to what your goal. I’ve got a question, your Number Value “player”, is it’s purpose to tally all the players that’d clicked the play button?

1 Like

It is used for two things, count how many players have clicked the “play” button and also it is used by another script to display the value on the player GUI, however the script doesn’t mess with the value at any moment, so I doubt that script is the problem, but if you want to check it out then there you go:

local players = game.Workspace.Players

while true do
	script.Parent.Text = players.Value .. "/15"
	wait(0.1)
end

Your problem is everything you are doing is on the client side and not the server side. To get it to work, you should fire a remote event over to the server to add and subtract the points there.

The server side is unable to see things changed on the client side, which is when remote events come in handy. They can pass data across the server for multiple uses.

2 Likes