Hello Everyone,
So I am working on a Minigame. All I going well until I had to start making the part of the script for detecting the winners.
gamewait = 20 -- How long to wait between minigames
hin = Instance.new("Hint")
mes = Instance.new("Message")
hin.Name = "GameHint"
mes.Name = "GameMessage"
Games = {"Original Sweeper","Sword Sweeper","Hammer Sweeper"} -- Model your minigames, and put their names here in their proper order!
hin.Parent = game.Workspace
Numofplayers = 2
hin.Text = "It is required to have at least " ..Numofplayers .." players in the server to start. If there is " ..Numofplayers .." or more players, your game will start shortly."
CheckSpawns = {"Spawn1","Spawn2","Spawn3","Spawn4","Spawn5","Spawn6"} --Put the name of your spawns for each minigame here. One of these lines for each minigame. In order! Make more of these.
Spawns = {CheckSpawns} -- The names of the groups of spawns go here in order of minigames!
Cuga = 0 -- Leave this alone!
Howto = {"Avoid the sweeper by jumping over it!"} -- Put the minigame(s) description here in order of your minigames!
Gamestucture = {game.Workspace:findFirstChild("Original Sweeper"):clone()} -- Nil value error
Gamestucture = {game.Workspace:findFirstChild("Sword Sweeper"):clone()}
Gamestucture = {game.Workspace:findFirstChild("Hammer Sweeper"):clone()} -- This allows the minigames to go into Workspace. One for each minigame. The name(s) must be right!
Waittime = {100} --- How much time is in each minigame in order!
Points = {1} ---How many points the minigames give in proper order
-- Put the name of the weapon group here. If there are no weapons, just put "".
for i=1, #Games do
game.Workspace:findFirstChild(Games[i]):remove()
end
function performrandom(gamenum)
for i=1, #Path do
path[i] = math.random(1, #Games)
end
end
while true do
if game.Players.NumPlayers > Numofplayers - 1 then
hin.Parent = game.Workspace
for i=0, gamewait do
hin.Text = "Next Game Starts In: " ..gamewait - i .." Seconds."
if game.Workspace:findFirstChild("Non") then
else
wait(1)
end
end
if game.Workspace:findFirstChild("Non") then game.Workspace:findFirstChild("Non"):remove() end
hin.Text = "Deciding Sweeper"
mes.Parent = game.Workspace
if game.Workspace:findFirstChild("Tag") then
if game.Workspace.Tag.Value < #Games + 1 then
Cuga = game.Workspace.Tag.Value
mes.Text = "An Game Decider Has Requested the Game To Be Game: " ..game.Workspace.Tag.Value
game.Workspace.Tag:remove()
wait(2)
end
else
for i=1, #Games do
mes.Text = Games[i]
wait(.1)
end
for i=1, #Games do
mes.Text = Games[i]
wait(.1)
end
for i=1, #Games do
mes.Text = Games[i]
wait(.1)
end
for i=1, #Games do
mes.Text = Games[i]
wait(.1)
end
Cuga = math.random(1, #Games)
--Starts Testcode #1
for i=1, Cuga do
mes.Text = Games[i]
wait(.1)
end
--Ends Testcode #1
--Cuga = performrandom(#Games)
--mes.Text = "Game is: " ..Games[Cuga] -->(REPLACED WITH TESTCODE #2)
mes.Text = "Sweeper is: " ..Games[Cuga]
wait(3.5)
end
if Howto[Cuga] ~= "" then
mes.Text = Howto[Cuga]
wait(4)
end
listPlayer = game.Players:GetChildren()
b = 1
for i=1, #listPlayer do
if b > #Spawns[Cuga] then b = 1 end
arf = listPlayer[i].Name
if game.Workspace:findFirstChild(arf) then
body = game.Workspace:findFirstChild(arf)
if body ~= nil then
if body:findFirstChild("Humanoid") and body:findFirstChild("Torso") then
--body.Torso.CFrame = Game.Workspace:findFirstChild(Spawns[Cuga]).CFrame
local teleportto=game.Workspace:findFirstChild(Spawns[Cuga][b])
if teleportto~=nil then
local torso = body.Torso
local location = {teleportto.Position}
local i = 1
local x = location[i].x
local y = location[i].y
local z = location[i].z
x = x + math.random(-2, 2)
z = z + math.random(-2, 2)
y = y + math.random(2, 5)
local cf = torso.CFrame
local lx = 0
local ly = y
local lz = 0
torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
end
end
end
end
b = b + 1
end
newworld = Gamestucture[Cuga]:clone()
newworld.Parent = game.Workspace
wait(.2)
--Starts Testcode #3A
playerchildren = game.Players:GetChildren()
for i=1, #playerchildren do
arf = playerchildren[i].Name
if game.Workspace:findFirstChild(arf) then
body = game.Workspace:findFirstChild(arf)
if body:findFirstChild("Torso") then
body.Torso.Anchored = false
end
end
end
--Ends Testcode #3A
if Weapons[Cuga] ~= "" then
for i=1, #listPlayer do
for a=1, #Weapons[Cuga] do
if game.Lighting:findFirstChild(Weapons[Cuga][a]) then
newwep = game.Lighting:findFirstChild(Weapons[Cuga][a]):clone()
newwep.Parent = listPlayer[i].Backpack
end
end
end
end
for i=1, #listPlayer do
local newtag = Instance.new("StringValue")
newtag.Name = listPlayer[i].Name
newtag.Parent = script
newtag.Value = "Winner"
local PlayerCheck = script.Parent.PlayerLeft:clone()
PlayerCheck.Disabled = false
PlayerCheck.Parent = newtag
end
mes.Text = "GO!"
--Starts Testcode #2B
for i=1, #playerchildren do
arf = playerchildren[i].Name
if game.Workspace:findFirstChild(arf) then
body = game.Workspace:findFirstChild(arf)
if body:findFirstChild("Torso") then
body.Torso.Anchored = false
end
end
end
--Ends Testcode #2B
if newworld:findFirstChild("Enabled") then
wait(6)
newworld:findFirstChild("Enabled").Value = 1
end
mes.Text = ""
i = 0
while i <= Waittime[Cuga] do
hin.Text = "Game Ends In: " ..Waittime[Cuga] - i .." Seconds."
i = i + 1
findchildren = script.Parent:findFirstChild("Game Script"):GetChildren()
if #findchildren > 1 then
else
i = Waittime[Cuga] + 1
end
wait(1)
end
childrenwinners = script.Parent:findFirstChild("Game Script"):GetChildren()
messagetosay = "Nobody"
for i=1,#childrenwinners do
if i > 1 then
messagetosay = messagetosay .." & " ..childrenwinners[i].Name
else
messagetosay = childrenwinners[i].Name
end
childrenwinners[i]:remove()
end
if #childrenwinners < 2 then
messagetosay = messagetosay .." has won!"
else
messagetosay = messagetosay .." have won!"
end
mes.Text = messagetosay
pointsperplayer = (Points[Cuga] * game.Players.NumPlayers) / #childrenwinners
for i=1,#childrenwinners do
if game.Players:findFirstChild(childrenwinners[i].Name) then
player = game.Players:findFirstChild(childrenwinners[i].Name)
if player~= nil then
if player.Character:findFirstChild("Torso") then
if player.Character.Torso:findFirstChild("roblox") then
if player.Character.Torso.roblox.Texture == "http://www.roblox.com/asset/?id=8157886" then
player.leaderstats.Points.Value = (player.leaderstats.Points.Value + (pointsperplayer))
end
end
end
player.leaderstats.Points.Value = player.leaderstats.Points.Value + (pointsperplayer)
end
end
end
newworld:remove()
wait(3)
mes.Text = ""
hin.Text = ""
else
mes.Text = ""
hin.Text = "It is required to have at least " ..Numofplayers .." players in the server to start. If there is " ..Numofplayers .." or more players, your game will start shortly."
end
wait(5)
end
I have found this script from another post but am having trouble understanding how they are detecting the winners. If someone could dissect the winners part and then explain it for me, that would be amazing. I am not asking for someone to make me a script but for someone to take this script I found and dissect the winners part and explain what is going on in it.
Thank you,
P.S. I would like to have my script so that there could be more than 1 winner.

2 comments
Well, messages are pretty much deprecated, meaning the will not work. Also
I know that.