Hello, basically for the game the system I have created is supposed to do as follows:
- The same image appears on multiple players screens (people inside of the player table)
- When a player types the correct answer to the image on their screen in chat, the round ends for all other players
- All players have their image and swapped to the next one on the list (and correct answer as well), and the cycle continues for a predetermined amount of times.
In order to accomplish this:
I first activate a remote event (server → client) to the certain players i want for the round, the remote event changes the players gui, and allows them to have their answer count when typed in chat.
When the correct answer is typed, another remote event is fired (client to server) and that remote event alerts all other players that someone has typed the correct answer, and forwards the round.
This is the local script:
wait(1)
RepStorage = game:GetService("ReplicatedStorage")
plr = game.Players.LocalPlayer
plrGui = plr.PlayerGui
plrImageHolder = plrGui:WaitForChild("GameGui"):WaitForChild("Frame"):WaitForChild("GuessItem")
Events = RepStorage:WaitForChild("Events")
RoundTick = Events:WaitForChild("SendRound")
RoundComplete = Events:WaitForChild("RoundComplete")
local function OnTick(item)
itemName = string.lower(item.Name)
plrImageHolder.Image = item.Image
print("Item sent: ", itemName)
RoundComplete.OnClientEvent:Wait()
itemName = nil
print("Round Ended")
end
plr.Chatted:Connect(function(message)
print(string.lower(message))
if string.lower(message) == itemName then
RoundComplete:FireServer()
end
end)
RoundTick.OnClientEvent:Connect(OnTick)
This is (part) of the server script
local function roundBegin(playerFolder, roundLength, fightFolder)
local list = listGenerate(fightFolder, RoundCount)
-- printItemList(list, fightFolder.Parent.Name)
for i = 1, roundLength do
print("Round", i)
local function OnComplete(player)
print(player, "scored")
for j, v in pairs(playerFolder) do --Alert other players someone has scored
RoundComplete:FireClient(playerTable[j])
end
end
RoundComplete.OnServerEvent:Connect(OnComplete)
for k, v in pairs(playerFolder) do
SendRound:FireClient(playerFolder[k], list[i])
end
RoundComplete.OnServerEvent:Wait()
wait(RoundCooldown)
end
end
wait(2)
playerTable = {game.Players["50ShadesOfLamps"]}
roundBegin(playerTable, RoundCount, fightFolder)
The problem is the line in the client script : “RoundComplete.OnClientEvent:Wait()”
It works fine the first 2 rounds of the match, but on the third, the script does not yield for the event to be called and flies right through, and stops the match from continuing. It is odd because the roundComplete function never even fires for a third time. (Which is also why the next round doesn’t start because the server script waits for the remote event to be fired before the next round will be began)
I have tried googling, and I have even tried ChatGPT and its come up dry.
Thanks for anyone who decides to help me.