Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to announce the winner of a round?

Asked by 6 years ago

Hey, I am making a game and it has 5-minute rounds. The leaderboard tracks something called team kills which is basically the number of kills the entire team got combined. My goal is to make it so that when each round ends, the game will figure out which team has more team kills and announce in a screen GUI who won. I have scripted the clock, leaderboard, weapons, arena, GUIs, and everything else successfully I just need help with the determining who won the game, announcing it after every game, then restarting the round (resets all players). If someone could help me with this that would be really appreciated. Thanks for your time.

Pertinent Details: The two teams are called Red and Blue (This might change later on but those are the names for right now) The Team Kills is an IntValue named Team kills which is also tracked on the leaderboard under Team Kills. It is stored in the Players section inside of a model called leaderstats.

VERY IMPORTANT: This is my working timer script if you could use this script, or even add on to it, to create the script I am asking for because I don't want to, and kind of can't change the time script because of the way my game is set up. So please just tell me what lines of code I need to add in and where to make this work.

repeat
        while true do
            wait(1)
            if script.Parent.Value == 0 then
                local map = game.Workspace.LaserArena
            map:Clone().Parent = game.Workspace
            wait(5)
            game.Workspace.LaserArena:Destroy()
            wait(5)
                script.Parent.Value = 300
                script.Parent.Value = script.Parent.Value -1
            else
                script.Parent.Value = script.Parent.Value -1
            end
        end
until character = nil

A full script would be extremely helpful but help to create one would be just as good. If you have any other questions regarding my question or if you want to see any of my other scripts from the game (like my leaderboard script, etc...), just ask in the comments or message me on Roblox, I will check both often so it probably won't take long for me to respond.

Thank you, Skyraider5

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago
local redkills = 0
local bluekills = 0

local UpdateEvent = Instance.new("RemoteEvent")
UpdateEvent.Name = "UpdateWinner"
UpdateEvent.Parent = game.ReplicatedStorage

for _,plr in pairs(game:GetService("Teams").Red:GetPlayers()) do
   redkills = redkills + plr.Backpack.leaderstats["Team kills"].Value
end
for _,plr in pairs(game:GetService("Teams").Blue:GetPlayers()) do
   bluekills = bluekills + plr.Backpack.leaderstats["Team kills"].Value
end
if redkills > bluekills then
    --red wins
    UpdateEvent:FireAllClients("Red")
elseif bluekills > redkills then
    --blue wins
    UpdateEvent:FireAllClients("Blue")
else
    --tie
    UpdateEvent:FireAllClients("Neither")
end

You would have to use remote events to update all the players' guis using FireAllClients(). This script would go towards the end of the round script after the round finishes.

To use the RemoteEvents, you could put a local script inside the text label gui that shows the winners of the match. In this local script, you could have the code:

game.ReplicatedStorage:WaitForChild("UpdateWinner").OnClientEvent:Connect(function(winner)
    script.Parent.Text = "The winner is " .. winner
end)

Then you could add the updated code in the top script. For more information on how the remote events work, you can look here.

0
So, what do I have to change about my current script, posted above, to make this script work? Would I have to add this script to mine, replace mine with this, or put parts of this in different parts of my current script? Also, I'm kinda new to this, what do you mean update the player's GUIs, what part of my question is that referring to? Thanks for you help. Skyraider5 -21 — 6y
0
If I am understanding you correctly, I think you are saying to put this after my current script, at the end of it right? Skyraider5 -21 — 6y
0
Also, one more question, correct me if I'm wrong, where you wrote --Red Wins (or --Blue Wins or --Tie) I would have to add in a code that makes the Screen GUI announcing the winner appear right? I can do that, there is no problem there but that is what i need to do correct? Skyraider5 -21 — 6y
0
Yes that is what you need to do, however it will probably require the usage of RemoteEvents to do this mattscy 3725 — 6y
Ad

Answer this question