|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 20 Jul 2015 01:12 PM |
why would that matter?
math.random is not working to select a random player, Period. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 20 Jul 2015 01:15 PM |
i tried that script, no work.
and yes i added the (). |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 22 Dec 2011 |
| Total Posts: 2347 |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 20 Jul 2015 02:07 PM |
| nQ is a respectable person around here |
|
|
| Report Abuse |
|
|
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 |
|
|