|
| 13 Dec 2016 04:17 PM |
I'm trying to select a random player and add a picture of their character to and imagelabel and add their account name to a textlabel. The script can only be tested if you have more than one player. I get this error when I test it:
: attempt to call local 'players' (a table value)
This is my script:
local players = game.Players:GetPlayers()
repeat wait() until #players > 1 local target = players(math.random(1, #players)) script.Parent.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..target.Name script.Parent.TextLabel.Text = target.Name for i=1, 5 do script.Parent.Position = script.Parent.Position + UDim2.new(0,41,0,0) wait() end |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 04:20 PM |
| change outer parentheses in to brackets |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 04:20 PM |
local target = players[math.random(1, #players)]
square brackets not round brackets
|
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 04:22 PM |
You use brackets to index a table not parenthesis
local table = {x = 5}
To index x it would be table[x] not table(x) |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Dec 2016 05:03 PM |
I probably should've made a new thread for this, but...
I'm tring to make the getplayer function repeat every 10 seconds if target = nil. The getplayer function is working however, the while do part is not. I haven't gotten any errors. Anyone know what's wrong with the script?
players = game.Players:GetPlayers()
function getplayer(getplayer) repeat wait() until #players > 1 repeat target = players[math.random(1, #players)] until target.Name ~= game.Players.LocalPlayer.Name script.Parent.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..target.Name script.Parent.TextLabel.Text = target.Name for i=1, 5 do script.Parent.Position = script.Parent.Position + UDim2.new(0,41,0,0) wait() end end getplayer(getplayer)
while wait(10) do if target == nil then getplayer() end end |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:09 PM |
:GetPlayers() returns a table of the CURRENT players when it's called. You only did it once so if there was only one player in the game and another came the player list would still be 1.
|
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:13 PM |
local par=script.Parent --convienence local target --might want this outside the function local function getPlayer() local players=game.Players:GetPlayers() --CURRENT players repeat wait() until #players>1 repeat target=players[math.random(#players)] until target.Name~=game.Players.LocalPlayer.Name par.Image="http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..target.Name par.TextLabel.Text=target.Name for i=1,5 do par.Position=par.Position+UDim2.new(0,41,0,0) --there is UDim2.new().lerp now wait() end end while true do --i really do prefer this. if not target then getPlayer() end wait(10) end
|
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:16 PM |
you also should add math.randomseed(tick()) to the top of your script as well since you are dealing with random numbers.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Dec 2016 06:01 PM |
The getPlayer function still isn't repeating.
This is the script currently:
math.randomseed(tick()) local target local function getPlayer() local players = game.Players:GetPlayers() repeat wait() until #players > 1 repeat target = players[math.random(#players)] until target.Name ~= game.Players.LocalPlayer.Name script.Parent.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..target.Name script.Parent.TextLabel.Text = target.Name for i=1,5 do script.Parent.Position = script.Parent.Position + UDim2.new(0,41,0,0) wait() end end while true do if not target then getPlayer() end wait(10) end |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 13 Dec 2016 06:02 PM |
why are you using a loop?
use PlayerAdded and PlayerRemoved
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Dec 2016 06:06 PM |
| ############################### |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Dec 2016 06:07 PM |
I swear to god my last half dozen posts have been censored.
Bobby, those are called braces.
|
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 06:59 PM |
| It doesn't really matter what you call them so long as people know what you're talking about, you're wrong either way because braces typically are 'curly brackets' - {} |
|
|
| Report Abuse |
|
|