#Matchmaking TextLabel doesnt change text. (Still Doesnt work need help)
1 messages · Page 1 of 1 (latest)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local MemoryStoreService = game:GetService("MemoryStoreService")
local TeleportService = game:GetService("TeleportService")
local joinQueueEvent = ReplicatedStorage:WaitForChild("GLSolo")
local updateQueueLabelEvent = ReplicatedStorage:WaitForChild("UpdateQueueLabelSolo")
local queue = MemoryStoreService:GetQueue("GlobalMatchQueue")
local MAX_PLAYERS = 4
local MATCH_PLACE_ID = 132817753335599
-- When a player clicks to join the queue
joinQueueEvent.OnServerEvent:Connect(function(player)
print(player.Name .. " is joining the global queue...")
local success, err = pcall(function()
queue:AddAsync(player.UserId, 60) -- player stays in queue for 60 seconds
end)
if not success then
warn("Queue add failed:", err)
end
end)
Script too long for me to send so Part 1
-- Matchmaker loop
task.spawn(function()
while true do
task.wait(5)
print("Matchmaker checking queue...")
local items = {}
local peekSuccess, peekErr = pcall(function()
items = queue:ReadAsync(MAX_PLAYERS, true)
end)
if peekSuccess then
local currentCount = #items
print("Queue has", currentCount, "players waiting.")
-- Fire updated count to all players
for _, plr in ipairs(Players:GetPlayers()) do
updateQueueLabelEvent:FireClient(plr, currentCount, MAX_PLAYERS)
end
-- Start match if full
if currentCount == MAX_PLAYERS then
local userIds = {}
local readSuccess, readErr = pcall(function()
userIds = queue:ReadAsync(MAX_PLAYERS, false)
end)
if readSuccess then
print("Match ready with:", table.concat(userIds, ", "))
local code
local reserveSuccess, reserveErr = pcall(function()
code = TeleportService:ReserveServer(MATCH_PLACE_ID)
end)
if reserveSuccess then
for _, userId in ipairs(userIds) do
local plr = Players:GetPlayerByUserId(userId)
if plr then
TeleportService:TeleportToPrivateServer(MATCH_PLACE_ID, code, {plr})
end
end
else
warn("Server reserve failed:", reserveErr)
end
else
warn("Queue read failed:", readErr)
end
end
else
warn("Queue peek failed:", peekErr)
end
end
end)
Part 2. It's a server script.
And lastly the local script:
local plr = game.Players.LocalPlayer
local button = plr.PlayerGui.MatchakingGUI.TextButton
local label = plr.PlayerGui.MatchakingGUI.PlayerText
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local joinQueueEvent = ReplicatedStorage:WaitForChild("GLSolo")
local updateQueueLabelEvent = ReplicatedStorage:WaitForChild("UpdateQueueLabelSolo")
button.MouseButton1Click:Connect(function()
print("Button clicked, requesting to join queue")
joinQueueEvent:FireServer()
end)
updateQueueLabelEvent.OnClientEvent:Connect(function(plr, current, max)
label.Text = current .. "/" .. max .. " Players"
end)
Obviously inside the replicated storage I have the remote event called: "UpdateQueueLabelSolo" that manages updating the text label.
The typo in the 2nd and 3rd line it the local script are okay, I made a typo in the name of the GUI so it's technically okay
So what does the label text display ?
Well it displays what it displays by normal: 0/4 Players
And once I click the Join Queue button, it doesnt change to 1/4 players.
If i am not mistaken, I think your problem may be in your OnClientEvent, since it should not pass trough the "plr" varible into it
so it should be like this instead
updateQueueLabelEvent.OnClientEvent:Connect(function(current, max)
label.Text = current .. "/" .. max .. " Players"
end)```
let me take a look
** You are now Level 1! **
Alright
A problem may be that your script dosent get the gui and label etc. Try changing it to waitforchild for extra securing
like this :
local gui = plr:WaitForChild("PlayerGui"):WaitForChild("MatchakingGUI")
local button = gui:WaitForChild("TextButton")
local label = gui:WaitForChild("PlayerText")
hmmm try putting some prints into the functions and events to see if the script even recives them
Well, the script has those prints that say "playername" is requesting to join the queue, and "playername" has joined a queue. And they all print
So should I add more?
add one into
updateQueueLabelEvent.OnClientEvent:Connect(function(current, max)
label.Text = current .. "/" .. max .. " Players"
end)
and see if the event prints it
then we'll know if it recives the call
Well thats good to know, then we'll know where we have to look
yep
where have you put your localscript?
So its inside the PlayerGui?
yes
Sorry i meant the starerGui Folder
yes
Is the screenGui its inside enabled?
Yes, it is
hmmm
so your OnClientEvent looks like this :
updateQueueLabelEvent.OnClientEvent:Connect(function(current, max)
label.Text = current .. "/" .. max .. " Players"
end)
and like this in server :
updateQueueLabelEvent:FireClient(plr, currentCount, MAX_PLAYERS)
** You are now Level 2! **
yes
then i really don't see the problem with your code i'm sorry
It's okay, I'll try to find it