generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Find Last Plr

Previous Thread :: Next Thread 
iiNemo is online. 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 is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 03:14 PM
b[1]
Report Abuse
Mister_Manakin is not online. Mister_Manakin
Joined: 16 Sep 2009
Total Posts: 1935
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 is online. 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 is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 03:28 PM
that = true
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 03:41 PM
b[2]
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 03:45 PM
b[3]
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 04:09 PM
b[4]
Report Abuse
DankosaurusReks is not online. DankosaurusReks
Joined: 21 Jul 2012
Total Posts: 67
18 Dec 2016 04:19 PM
kid make it clearer for us


Report Abuse
iiNemo is online. 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 is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 04:53 PM
Explained enough?
Report Abuse
JoshRBX is not online. 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 is online. 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 is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 05:50 PM
b[4]
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
18 Dec 2016 06:08 PM
b[5]
Report Abuse
XCVlll is not online. 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 is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
18 Dec 2016 06:41 PM
woops, add spawn(win) at the end
Report Abuse
XCVlll is not online. 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 is not online. 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 is online. 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 is not online. 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 is online. 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 is not online. 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
Xstarlight is not online. Xstarlight
Joined: 18 Oct 2012
Total Posts: 870
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
Xstarlight is not online. Xstarlight
Joined: 18 Oct 2012
Total Posts: 870
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image