Hello, my Round System isn’t working roperly and i dont know why. so some explanation: I was testing my round system with a friend and it seems like all players have to leave the server for somebody to win and not after everyone has died and i dont know how to fix that! it wouldbe helpfull if somebody could fix this code or help me fix it (i appreciate both tbh).
here is my code:
local intermission = 10
local roundLength = 120
local inRound = game.ReplicatedStorage.InRound
local status = game.ReplicatedStorage.Status
local TC = game.ReplicatedStorage.TC
local function SetStatusMessage(message)
status.Value = message
end
local function SetTextMessage(message)
TC.Value = message
end
local function TeleportToSpawnPoint(spawnPoint)
if spawnPoint == nil then return end
for _, v in pairs(game:GetService("Players"):GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = spawnPoint
end
end
inRound.Changed:Connect(function()
if inRound.Value == true then
SetStatusMessage("In Round")
TeleportToSpawnPoint(game.Workspace.DropGame.RoundSpawn.CFrame)
else
SetStatusMessage("In Lobby")
TeleportToSpawnPoint(game.Workspace.Lobby.LobbySpawn.CFrame)
end
end)
local function round()
while true do
local requiredPlayers = 2
repeat
wait(1)
SetStatusMessage("Waiting for players...")
until #game.Players:GetPlayers() >= requiredPlayers
inRound.Value = false
for i = intermission, 0, -1 do
SetStatusMessage("Game will start in "..i.." seconds")
wait(1)
end
inRound.Value = true
local roundEnded = false
local winningPlayer = nil
for i = roundLength, 0, -1 do
SetStatusMessage("Game will end in "..i.." seconds")
local playing = {}
for _, plr in pairs(game.Players:GetPlayers()) do
if not plr.Team then
table.insert(playing, plr)
end
end
if #playing == 0 then
SetStatusMessage("Everyone Has Died")
roundEnded = true
break
end
if #playing == 1 then
local winner = playing[1]
SetStatusMessage(winner.Name.." Has Won The Game!")
winningPlayer = winner
roundEnded = true
break
end
wait(1)
end
if not roundEnded then
SetStatusMessage("The round has ended")
end
if winningPlayer then
local randomCoins = math.random(20, 100)
winningPlayer.leaderstats.Wins.Value += 1
if winningPlayer.MembershipType == Enum.MembershipType.Premium then
randomCoins = randomCoins * 2
end
winningPlayer.leaderstats.Coins.Value += randomCoins
TC.Archivable = true
if winningPlayer.MembershipType == Enum.MembershipType.Premium then
SetTextMessage("You have gotten "..randomCoins.."! (Double Coins Premium)")
else
SetTextMessage("You have gotten "..randomCoins.."!")
end
wait(4)
TC.Archivable = false
end
wait(3)
end
end
spawn(round)
5 Likes
I think it’s because you are checking for the players in players service here:
This means you are checking if there is one player in the game since for player to be removed from player service they have to leave. Instead you can use the characterRemoved function to remove the dead players from the table and send them to the lobby.
5 Likes
Thanks for letting me know whats the misstake but may you give the fixxed piece of code i need? I’m not that great of a coder and thats also why. Would be nice ![:grin: :grin:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/grin.png?v=12)
![:+1: :+1:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/+1.png?v=12)
2 Likes
no one’s gonna write the code for you. If you need to separate the player from the others, you should just use localplayer instead
2 Likes
Then just give an example of the changes i have to make because i’m not that experienced man you could like tell the line and why i have to replace it with to may get it work but your answer doesnt have to be as rude as you made it.![:unamused: :unamused:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/unamused.png?v=12)
![:neutral_face: :neutral_face:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/neutral_face.png?v=12)
2 Likes
may you give an example of how i could use the function since im preatty new to scripting?
2 Likes
Maybe it works like that because you forgot to set the inRound value back to normal.
Try doing that at then end of the round.
Imma have a look and ill tell you if i dont undestand it or unserstand it in hope tat you may help me
This might work if you alter it too:
local connection
for _, player in pairs(Game:GetService(“Players”):GetChildren())
local char = player.Character
connection = char:WaitForChild(“Humanoid”).Died:Connect(function() – runs the function when player has died
print(player.Name … " has died!")
if table.find(survivalwinners, player.Name) then – wont run if the player isn’t in the table
connection:Disconnect() – This part makes it so if the same player dies again the script wont run. This also reduces lag so yes. If you want to make it so the script keeps running even though the player has died once then remove this part
local location = table.find(survivalwinners, player.Name) – gets the location of player in table
table.remove(survivalwinners, location) – removes the player from tabl
end
end)
end
I’ve came up with a solution:
local playing = {}
local lobby = {}-- Create an empty table to store playing players
-- Loop through all players in the game
for _, plr in pairs(game.Players:GetPlayers()) do
-- Check if the player has a team (is playing)
if not plr.Team then
inRound.Value = true
table.remove(lobby, plr)
table.insert(playing, plr)
Checking.Value = true
else
inRound.Value = true
table.remove(playing, plr)
table.insert(lobby, plr)
Checking.Value = false
end
end
but it ened up not working and the timmer for round just stopped may you help me?
whith what should i replace it with
I’m pretty sure it’s because you are removing the player directly from the plr value, I think you need to use table.find to retrieve the index of that specific player. Also what’s the point of having a lobby and a playing table? If the player is in the game it is certain that they are in the lobby
can you show an example on how it could/should look?
This might not work:
(Sorry if this doesn’t work I wrote it on mobile.)
Local character = game:GetService(“Players”).Character or CharacterAdded:Wait()
for i, player in pairs(game:GetService(“Player”):GetChildren()
Table.insert(Playing, player.Name)
character.CharacterRemoving:Connect(Function()
If table.find(Playing, player.Name) then
PlayerLocationInTable = table.find(Playing, player.Name)
table.remove(Playing, PlayerLocationInTable)
End
End)
End```
is this just an example or can i replace it with smth?
You probably can use it but it might need some adjustment or fixing some things up
Roblox gave me this script:
local playing = {}
local lobby = {}-- Create an empty table to store playing players
for _, v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Team == game.Teams.Playing then
table.insert(playing, v)
elseif v.Team == game.Teams.Lobby then
table.insert(lobby, v)
end
end
if #playing <= 1 and not roundEnded then -- If there is only one player left playing the game...
roundEnded = true -- Set the round as ended.
winningPlayer = playing[1] -- The winning player is the last remaining player.
elseif i == 0 and not roundEnded then -- If time has run out and no winner has been found...
roundEnded = true --
-- Now, the 'playing' table contains all the players who are currently playing
-- You can use this 'playing' table for further processing or checks
but then at the end of the code this here gets marked red (justs the (round)):
spawn(round)
I still think you should just put the inRound value back to normal instead of adding all the other unnecessary things.
May you give and example what i may input in there instead of this all??