Value not changing

I am trying to make a GUI that pops up every 5 minutes, notifying you that a brawl is about to start. It has a button to join and leave the brawl, and a queue number for the amount of people joining the brawl.

The problem I am experiencing is that when you click the Join button, the Players value doesn’t change, which prevents the queue from changing, too.

local MainFrame = script.Parent.MainFrame
MainFrame.Queue.Text = "Queue: "..MainFrame.Queue.Players.Value.." Players"

MainFrame.Join.MouseButton1Click:Connect(function()
	MainFrame.Leave.Visible = true
	MainFrame.Queue.Players.Value = MainFrame.Queue.Players.Value + 1
end)

MainFrame.Leave.MouseButton1Click:Connect(function()
    MainFrame.Leave.Visible = false
    MainFrame.Queue.Players.Value = MainFrame.Queue.Players.Value - 1
end)

This is my first post! (Technically)

You’re looking in the wrong place for the value. In the video, you’re looking under the StarterGui section, but this section is actually replicated to Player.PlayerGui

If you want to see the value update, you’re going to have to open up the Players, find your player, open PlayerGui, and find the value where it’s supposed to be. As a general tip though, if you’re trying to set up a queue/player match system, I’d recommend having the value on the server since local changes to values don’t replicate to other people.

Hope this helps! :slight_smile:

3 Likes

Thanks! Oh, and by the way, in case you haven’t noticed, I haven’t implemented the 5 minute part yet, but you can tell me how if you want, even though you don’t have to!

1 Like

Update: The value now changes, but the text doesn’t.

I noticed that you’re using a regular script for your Gui. You should not be doing this. When it comes to Gui work, you should be working with LocalScripts and anything that’s intended to influence the game should be facilitated via a RemoteEvent.

In your case, the LocalScript should be detecting input while the RemoteEvent and a server script should be registering queue joins and leaves.

No, I switched it to a LocalScript.

You have to edit the text everytime either of your buttons are clicked; Setting the text once will not change the text everytime.

local MainFrame = script.Parent.MainFrame
MainFrame.Queue.Text = "Queue: "..MainFrame.Queue.Players.Value.." Players"

MainFrame.Join.MouseButton1Click:Connect(function()
	MainFrame.Leave.Visible = true
	MainFrame.Queue.Players.Value = MainFrame.Queue.Players.Value + 1
   MainFrame.Queue.Text = "Queue: "..MainFrame.Queue.Players.Value.." Players"
end)

MainFrame.Leave.MouseButton1Click:Connect(function()
    MainFrame.Leave.Visible = false
    MainFrame.Queue.Players.Value = MainFrame.Queue.Players.Value - 1
    MainFrame.Queue.Text = "Queue: "..MainFrame.Queue.Players.Value.." Players"
end)

OR


local MainFrame = script.Parent.MainFrame
function update()
    MainFrame.Queue.Text = "Queue: "..MainFrame.Queue.Players.Value.." Players"
end
update()

MainFrame.Join.MouseButton1Click:Connect(function()
	MainFrame.Leave.Visible = true
	MainFrame.Queue.Players.Value = MainFrame.Queue.Players.Value + 1
    update()
end)

MainFrame.Leave.MouseButton1Click:Connect(function()
    MainFrame.Leave.Visible = false
    MainFrame.Queue.Players.Value = MainFrame.Queue.Players.Value - 1
    update()
end)

My response still stands. With a LocalScript, changes to a value will not be replicated and only the client will be able to see the change. You need to interface with a RemoteEvent so that the value change can be seen by other clients as well.

2 Likes

So… the GUI text won’t be shown on other clients?

No, it won’t, UNLESS you use a RemoteEvent or another safe way to tell the server that the value has changed. Then you can use :FireAllClients() to send the value to each client.

2 Likes

Alright, I don’t know what to do at this point, since I’m pretty sure my code will only work if it’s in a LocalScript, which is where the code is right now… and you need to be using a ServerScript for it to work, so… what am I gonna do?

MainFrame.Queue.Players.Changed:Connect(function()
    MainFrame.Queue.Text = "Queue: "..MainFrame.Queue.Players.Value.." Players"
end)

Make sure the “Players” value is accessible to every client, such as in replicated storage. Use a remote event to increment/decrement the count when a player joins or leaves the queue.