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: umm

Previous Thread :: Next Thread 
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:08 PM
Is it even possible these days to select a random player using math.random?

every thing i try i get the interval error.

also the scripts work in studio but it is the actual server that i get that error..
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 01:10 PM
Post the script plez C:
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 01:12 PM
However you could try this:

players = game.Players:GetChildren

randomplayer = players[math.random(1,#players)]
print(randomplayer) -- this part isn't necessary
Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:12 PM
why would that matter?

math.random is not working to select a random player, Period.
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 01:12 PM
forgot the () after GetChildren, woops...


players = game.Players:GetChildren()

randomplayer = players[math.random(1,#players)]
print(randomplayer) -- this part isn't necessary
Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:15 PM
i tried that script, no work.

and yes i added the ().
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 01:19 PM
Hmmm... that's strange because my game also requires picking a player at random and it works fine for me... Here's the script:

a = {}
b = {}

function GetPeeps()

a = {}
b = {}

for i, v in pairs (game.Players:GetChildren()) do
if v:FindFirstChild("PlayerGui") then
if v.TeamColor.Name == "Bright yellow" then
table.insert(a,v.Name)
end

if v.TeamColor.Name == "Bright green" then
table.insert(b,v.Name)
end
end
end
end

function CapA()
local n = math.random(1,#a)
if game.Players:FindFirstChild(a[n]) then
workspace.TeamPicking.ACap.Value = a[n]
else
GetPeeps()
CapA()
end
end

GetPeeps()
CapA()


Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:34 PM
based from what you posted, i made a script.
however it doesnt seem to work ether.

u = {}
game.Players.PlayerAdded:connect(function()
h = game.Players:GetChildren()
table.insert(u,h.Name)
local n = math.random(1,#u)
local p game.Players:FindFirstChild(u[n])
p.Name:print()
end)
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 01:37 PM
Is there anything in output? Also that script wouldn't remove players from the table (u) once they leave, just a heads up.
Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:39 PM
error:

14:38:44.086 - Workspace.Random Player:5: bad argument #2 to 'random' (interval is empty)
14:38:44.088 - Script 'Workspace.Random Player', Line 5
14:38:44.090 - Stack End
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
20 Jul 2015 01:39 PM
lol kid
Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:42 PM
@nQqzRYVpIKA5jLP
says the n00b who just joined roblox.
you dont even know how to script, so gtfo scrub.
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 01:43 PM
u = {}
game.Players.PlayerAdded:connect(function()
h = game.Players:GetChildren()
for i, v in pairs (h) do
table.insert(u,v.Name)
end
local n = math.random(1,#u)
local p = game.Players:FindFirstChild(u[n])
print(p.Name)
end)
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
20 Jul 2015 01:44 PM
u = {}
game.Players.PlayerAdded:connect(function()
h = game.Players:GetChildren()
table.insert(u,h.Name)
local n = math.random(1,#u)
local p game.Players:FindFirstChild(u[n])
p.Name:print()
end)


---Really?

h = game.Players:GetChildren()

How are you going to insert the name of h?
try this instead:

u = {}
game.Players.PlayerAdded:connect(function(plr)
h = game.Players:GetChildren()--What is this for?
table.insert(u,plr.Name)--inserting the actual player's name
local n = math.random(1,#u)
local p = game.Players:FindFirstChild(u[n]) -- you forgot a '='
p.Name:print()
end)


Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
20 Jul 2015 01:46 PM
and make h local
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
20 Jul 2015 01:46 PM
Here is how you choose a random player

local function PickRandomPlayer()
local Players = game:GetService("Players"):GetPlayers();
local RandomPlayer = Players[math.random(1,#Players)]
return RandomPlayer
end

example use:

local Random = PickRandomPlayer()
print(Random.Name)


I script for free and help out whenever possible!
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
20 Jul 2015 01:47 PM
I didnt even notice this part:

p.Name:print()


What is that??????

print(p.Name)
Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 01:56 PM
@cgjnm

i dont need your crap, ZIFDevelopment already posted a fixed copy of the script befor you c:

also i didnt notice the "=" missing.
And i forgot how to do the print command soz.
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
20 Jul 2015 01:59 PM
Don't need my crap?

If you don't want feedback and help, don't post on forums...
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
20 Jul 2015 02:00 PM
And ZIF's script wouldn't work


He has it so that every time a player joins, it will add all players AGAIN to the table
Report Abuse
ZIFDevelopment is not online. ZIFDevelopment
Joined: 14 Jul 2015
Total Posts: 18
20 Jul 2015 02:01 PM
u = {}
game.Players.PlayerAdded:connect(function()
u = {} -- this will make sure that players who left the game are not considered and players aren't added twice
h = game.Players:GetChildren()
for i, v in pairs (h) do
table.insert(u,v.Name)
end
local n = math.random(1,#u)
local p = game.Players:FindFirstChild(u[n])
print(p.Name)
end)
Report Abuse
GameDevelopment4706 is not online. GameDevelopment4706
Joined: 20 Jan 2011
Total Posts: 306
20 Jul 2015 02:03 PM
thats why i have a new version:
u = {}
while true do
wait()
if game.Players.NumPlayers > 0 then
h = game.Players:GetChildren()
for i, v in pairs (h) do
table.insert(u,v.Name)
end
local n = math.random(1,#u)
local p = game.Players:FindFirstChild(u[n])
print(p.Name)
wait(2)
end
end

time 2 test in-game to see if this works, in studio it prints the name of "Player1" without no errors.
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
20 Jul 2015 02:04 PM
LOL this kid
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
20 Jul 2015 02:07 PM
nQ is a respectable person around here
Report Abuse
Iskarik is not online. Iskarik
Joined: 28 Jun 2012
Total Posts: 123
20 Jul 2015 02:07 PM
"@nQqzRYVpIKA5jLP
says the n00b who just joined roblox.
you dont even know how to script, so gtfo scrub."

I'd say that nQqzRYVpIKA5jLP is one of the best Scripters on the Forums.

I have a low RAP
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