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 » Scripting Helpers
Home Search
 

Re: Randomly player picker doesnt choose 2 people?

Previous Thread :: Next Thread 
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 03:09 PM
So heres what I have, and at the if then, it skips to the else and just keeps repeating the whole script.. how could I make sure the random at the beginning chooses two DIFFERENT people?

function startgame()


local p2 = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]
local p3 = p2.Name
local p4 = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]
local p5 = p4.Name

if p3 ~= p5 then
blah blah blah
else
lopping stuffs.

~ http://www.roblox.com/Devils-Partner-item?id=78350231 ~
Report Abuse
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 03:22 PM
bump?

site.Accounts.callmeduck2.PostCount.Value=site.Accounts.callmeduck2.PostCount.Value+1
Report Abuse
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 03:38 PM
:/

site.Accounts.callmeduck2.PostCount.Value=site.Accounts.callmeduck2.PostCount.Value+1
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
24 Apr 2012 03:41 PM
Try:

local p2 = Game.Players:GetPlayers()[math.random(#game.Players:GetPlayers())]
local p3 = Game.Players:GetPlayers()[math.random(#game.Players:GetPlayers())]

repeat wait() until p2 ~= p3

?

† KMXD †
Report Abuse
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 03:42 PM
I have. It just keeps going.. and going... and going...

site.Accounts.callmeduck2.PostCount.Value=site.Accounts.callmeduck2.PostCount.Value+1
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
24 Apr 2012 03:43 PM
Try mine... It's different :S

† KMXD †
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
24 Apr 2012 03:47 PM
Close...

repeat
local p2 = Game.Players:GetPlayers()[math.random(#game.Players:GetPlayers())]
local p3 = Game.Players:GetPlayers()[math.random(#game.Players:GetPlayers())]
wait() until p2 ~= p3


I normally test this stuff before I post them... Sorry if it doesn't work..
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
24 Apr 2012 03:53 PM
@Game

Oh, that seems better I guess.

† KMXD †
Report Abuse
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 03:55 PM
still keeps going.. and going.. and going.. :/

site.Accounts.callmeduck2.PostCount.Value=site.Accounts.callmeduck2.PostCount.Value+1
Report Abuse
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 04:00 PM
): anyone got some freemodelz I can look at concerning this? ;o

site.Accounts.callmeduck2.PostCount.Value=site.Accounts.callmeduck2.PostCount.Value+1
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Apr 2012 04:07 PM
There's a simple algorithm that you can use to select to random players through a table.

repeat
  wait()
until
  Game.Players.NumPlayers > 1

local players = loadstring([==[local t = {} for i,v in next, Game.Players:GetPlayers() do t[v] = v end return t]==])()

if #players > 2 then
p1 = players[math.random(1, #players)]
table.remove(players, p1)
p2 = players[math.random(1, #players)]
else
p1, p2 = players[1], players[2]
end

That is a fail-safe. So I believe it should have no problems now, or in the future.
Report Abuse
callmeduck2 is not online. callmeduck2
Joined: 18 Jan 2010
Total Posts: 2804
24 Apr 2012 04:16 PM
Like this? because it's still not choosing 2 different people..

local m = Instance.new("Message")
local p = game.Players
local plyrs = 2 -- number of players needed to start game :3
------------------------------------------------------------

function startgame()

repeat
wait()
until
Game.Players.NumPlayers > 1

local players = loadstring([==[local t = {} for i,v in next, Game.Players:GetPlayers() do t[v] = v end return t]==])()

if #players > 2 then
p1 = players[math.random(1, #players)]
table.remove(players, p1)
p2 = players[math.random(1, #players)]
else
p1, p2 = players[1], players[2]
end

local p3 = p2.Name
local p5 = p4.Name

print("enough")

wait(4)
m.Text = p3.. " and " ..p5.. " have been chosen!"
wait(4)
p2.Character.Torso.CFrame = CFrame.new(Vector3.new(game.Workspace.Duel1.Position))
p4.Character.Torso.CFrame = CFrame.new(Vector3.new(game.Workspace.Duel2.Position))
m.Text = "Get ready..."
wait(4)
m.Text = "...3..."
wait(1)
m.Text = "..2.."
wait(1)
m.Text = ".1."
wait(1)
m.Text = "GO!"
wait(.5)
m:remove()
wait(1)
endgame()
end

function endgame()


end



site.Accounts.callmeduck2.PostCount.Value=site.Accounts.callmeduck2.PostCount.Value+1
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
24 Apr 2012 04:25 PM
No...not like that, which is my mistake. The operation of counting a table's length cannot be done with non-numerical indexes.

function GetCount(Table)
local t = Table
local c = 0
for i,v in next, Table do
c = c + 1
end
return c
end

function GetRandom(Table)
local ps = {}
for i,v in next, Table do
table.insert(ps, v)
end
return ps[math.random(1, #ps)]
end

repeat
wait()
until
Game.Players.NumPlayers > 1

local players = loadstring([==[local t = {} for i,v in next, Game.Players:GetPlayers() do t[v] = v end return t]==])()

if GetCount(players) > 2 then
p1 = GetRandom(players)
table.remove(players, p1)
p2 = GetRandom(players)
else
p1, p2 = Game.Players:GetPlayers()[1], Game.Players:GetPlayers()[2]
end
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
24 Apr 2012 05:00 PM
Ok. I tested this and it seems to work. Except I don't know how you intend to start the game up again. I also don't know if startgame() is called somewhere else in your script... So it's at the bottom.


local m = Instance.new("Message")
local p = game.Players
local plyrs = 2 -- number of players needed to start game :3
------------------------------------------------------------

function startgame()

repeat
wait()
until
Game.Players.NumPlayers > 1

local players = p:GetPlayers()

if #players > 2 then
r1 = math.random(1, #players)
p1 = players[r1]

table.remove(players, r1)

r2 = math.random(1, #players)
p2 = players[r2]
else
p1, p2 = players[1], players[2]
end

local p3 = p1.Name
local p5 = p2.Name

print("enough")

wait(4)
m.Parent = workspace
m.Text = p3.. " and " ..p5.. " have been chosen!"
wait(4)
p2.Character.Torso.CFrame = CFrame.new(Vector3.new(game.Workspace.Duel1.Position))
p4.Character.Torso.CFrame = CFrame.new(Vector3.new(game.Workspace.Duel2.Position))
m.Text = "Get ready..."
wait(4)
m.Text = "...3..."
wait(1)
m.Text = "..2.."
wait(1)
m.Text = ".1."
wait(1)
m.Text = "GO!"
wait(.5)
m:remove()
wait(1)
endgame()
end

function endgame()


end

startgame()

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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