iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 18 Dec 2016 02:45 PM |
| So basically, their is a bool value(true or false value) named Game in every player. I want a script too loop until theirs 1 player left with the bool value to = true and it will be able to print its player name, anyone help? It would be easiest if it could be a table where it would organise all players so I could do plr[1] = first place plr[2] = second place and yea.. sooo anyone help :3 |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
|
| 18 Dec 2016 03:16 PM |
for i,v in pairs(game.Players:GetPlayers()) do if (v:FindFirstChild("Game") and v.Game.Value) then print(v.Name) end end |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 18 Dec 2016 03:27 PM |
| I want it to find the Last Player with it not just print the players with the value |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
|
| 18 Dec 2016 04:19 PM |
kid make it clearer for us
|
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 18 Dec 2016 04:45 PM |
I want it to find the last player alive in the game. SO basically I want a script to loop until it finds the last player with a value called Game.
EX: The Game Value is located in game.Players.iiNemo, its a true or a false value. True means alive false means dead. |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
|
| 18 Dec 2016 04:58 PM |
| Just make a script that iterates through the player values, and if the amount of true values is equal to 1, then you have your winner. |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 18 Dec 2016 05:44 PM |
| Could u make it more clear or just do the work for me :3 |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
| |
|
XCVlll
|
  |
| Joined: 23 Oct 2008 |
| Total Posts: 963 |
|
|
| 18 Dec 2016 06:38 PM |
im feeling tired but try this, it might not even work
counted = {}
for _,v in pairs(game.Players:GetChildren()) do if v:FindFirstChild("Game") then if v["Game"].Value then for i,p in pairs(counted) do if v.Name ~= p[i] then table.insert(counted,v.Name) end end end end end
function died() while wait() do for _,v in pairs(game.Players:GetChildren()) do if v:FindFirstChild("Game") then if not v["Game"].Value then for i,p in pairs(counted) do if v.Name == p[i] then table.remove(counted,v.Name) end end end end end end end spawn(died)
function win() while wait() do for _,v in pairs(game.Players:GetChildren()) do if v:FindFirstChild("Game") then if v["Game"].Value then if #counted == 1 then print(v.Name.."has won!") end end end end end end |
|
|
| Report Abuse |
|
|
XCVlll
|
  |
| Joined: 23 Oct 2008 |
| Total Posts: 963 |
|
|
| 18 Dec 2016 06:41 PM |
| woops, add spawn(win) at the end |
|
|
| Report Abuse |
|
|
XCVlll
|
  |
| Joined: 23 Oct 2008 |
| Total Posts: 963 |
|
|
| 18 Dec 2016 06:43 PM |
| make sure you clear the table at the end of the game after the winner is selected. also, be sure to disable and re-enable the script at the start of a new round/game |
|
|
| Report Abuse |
|
|
XCVlll
|
  |
| Joined: 23 Oct 2008 |
| Total Posts: 963 |
|
|
| 18 Dec 2016 06:45 PM |
| oh and ill explain my code in case you don't understand. simply put, the script adds everyone who's alive to the table at the start of the game. then, the game removes anyone who dies from the table. at last, the game print's the winner's name when the table only has 1 person's name in it |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 18 Dec 2016 06:48 PM |
| Thanks for taking your time to waste your life for that but when I put it in, no errors and noting happens... |
|
|
| Report Abuse |
|
|
XCVlll
|
  |
| Joined: 23 Oct 2008 |
| Total Posts: 963 |
|
|
| 18 Dec 2016 06:50 PM |
| try testing it using start server then have about 1-3 players. then make sure the script is disabled at first, enable the script whenever the game actually starts |
|
|
| Report Abuse |
|
|
iiNemo
|
  |
| Joined: 22 Jul 2013 |
| Total Posts: 2380 |
|
|
| 18 Dec 2016 06:53 PM |
| k join my game to help meh test :3 |
|
|
| Report Abuse |
|
|
XCVlll
|
  |
| Joined: 23 Oct 2008 |
| Total Posts: 963 |
|
|
| 18 Dec 2016 06:53 PM |
| you don't want to just have it running if the game isn't starting because then it'd count people as alive before they even load into the game |
|
|
| Report Abuse |
|
|
|
| 18 Dec 2016 06:58 PM |
while true do print("Stop asking us and learn how to script.") wait() local players = game.Players:GetChildren() local alive = 0 for i=1, #players do if players[i].Game.Value == true then alive = alive + 1 end end if alive == 1 then print("Only one player alive, ending!") end end |
|
|
| Report Abuse |
|
|
|
| 18 Dec 2016 07:01 PM |
Actually replace:
"if alive == 1 then print("Only one player alive, ending!") end"
with:
if alive == 1 then print("Only one player alive, ending!") break end |
|
|
| Report Abuse |
|
|