I am currently making a game and working myself hard on it, and at the moment i need to make the main scripts wich is kind of a minigame script.
Basically i need to do this:
Rounds System
Map Voting Screen
Last one Standing wins
Repeat
What i need help is how to make all those things, i have an idea but iâm not sure if itâll work and i donât want to waste a lot of time doing something and not working at then end.
Also i wish on adding multiple gamemodes but they all end with the last person standing so if you include how to make multiple gamemodes i would appreciate.
If anyone wants more information i am open for questions, thanks!
Last one standing is just putting every player in a table, teleporting them if they got a character otherwise waiting a limited time on them, then putting functions on every one of them with a connection;
Every time one person dies you go through the table and remove them from it and at the same time detect if only one player is still standing, if they still are alive after ⊠seconds then he won.
For it to repeat, you would have every minigameâs name / function to make it start inside an array and do something like
if #miniGamesArray >= 1 then
miniGamesArray[math.random(1, #miniGamesArray)]
end
Then the map voting is just making the players be able to vote between a certain amount of maps or every map, I suggest the first option. Then you send a message to every client and make a GUI pop-up with all the map thumbnails, then once a player clicks on it it sends a message to the server.
You can either make it so that their vote is locked or they can change vote.
Another thing, is being able to see what everyone voted, at the end (like in among us) or not and only the winning map.
Locking in votes (not being able to change your vote) or being able to change your vote.
See the player amount of who voted for this map, see at the end who voted for what/the amount of votes or only tell the players which map won the vote (without telling them the amount of votes).
2.1. An idea is something like among us for the first and second option, showing the playerâs avatar pictures in an ImageLabel or characters in a ViewportFrame.
Let them vote every map or let them vote X randomized maps, with X < #Maps.
I meant more information about the âLast one Standingâ part. Thatâs the part iâm having more trouble comprehending (sorry if i wrote that wrong). I just want more clear information on how i can do the last one standing part.
I couldnât tell you if it worked or not because I havenât tested it.
local playersingame = {};
-- a utility function to remove a player from playersingame by value, rather than key
local removeplayer = function(player)
for a, x in pairs(playersingame) do
if(x == player)then
table.remove(playersingame, a);
end
end
end
-- round start
for a, x in pairs(game.Players) do
-- insert all players into the game
table.insert(playersingame, x);
end
-- register a function to be called by any player in-game who dies
for a, x in pairs(playersingame) do
local death;
death = x.Character.Humanoid.Died:connect(function()
death:disconnect();
x.Team = game.Teams.Out;
removeplayer(x);
end)
end
-- ... do whatever you have to do to setup the game
-- main game loop
while wait() do
-- since this is the game loop, we should check whether more than 1 player is left
-- if not, then the game is over
if(#playersingame == 1)then
print("Round is over! " .. playersingame[1].Name .. " won!");
playersingame = {};
break;
elseif(#playersingame < 1)then
print("Round is over! It's a draw!");
playersingame = {};
break;
end
-- if we make it to this point, the game is still ongoing
-- do game stuff
end
-- round ended; reset the script by reenabling it from another script (or rewrite this code as a function)
script.Disabled = true;
Alright, so you would put all the stuff in a while true do loop, as you want it to repeat.
You would simply make a for i loop for the Rounds-System.
For the Map Voting Screen, you would just tween a gui onto the screen, make a table, check if the guy who is trying to click an option has already voted, if no, then add one vote to that variable/intValue.
The last one standing part will be the hardest, probably.
Iâd assign a value to all of the playerâs character (as when you die, your character gets resetted which means that value will get removed) and then check every second (you can do that inside of the for i loop) who has those values inside of their characters. If itâs only one player, then he is the winner.
You shouldnât worry that much about the spawns, youâd just make a lobby and add some spawns to it, whenever the round starts, youâd just iterate through all the players and set their HumanoidRootPartâs position to the map. After they die, they would spawn in the lobby.
Use these:
CFrameâs
math.random
while true do or while wait(1) do
if ⊠> number then
repeat and until
for i = number,secondnumber,thirdnumber do
local players = game.Players:GetChildren()
for i = 1,#players do
(I cant actually send a hole entire script for you to copy but, this might help you.)
Oh yes, sorry I thought you were talking about a BasePart, what you should do is the following:
Put every playerObject in a array.
local alive = game:GetSerivce("Players"):GetPlayers()
Go through the table with a for loop
local function checkForWin(table)
if #table == 0 then return end -- check if 0 players are alive
if #table > 1 then return end -- check if the player amount isn't higher than 1
wait(.5)
if #table == 0 then return end -- check if the player really didn't die
return table[1]
end
for index,player in pairs(alive) do
if not player.Character then -- it might has to be player:FindFirstChild("Character")
table.remove(index,alive)
end
player.Character.Died:Connect(function()
table.remove(index,alive) -- this might fail as the player's index migh've changed if he had index 2 and index 1 died.
end)
spawn(function() -- so the for loop doesn't have to wait for this.
local winPlayer = checkForWin(alive)
if winPlayer ~= nil then
print(winPlayer.Name.." has won!")
end
end)
end