OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:03 PM |
I know some stuff about scripting, and I somewhat understand this for statement, but what on Earth is the '_,' or 'in pairs' ? Please someone explain this to me.
#code "Thanks in advance" -- Online |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2016 07:04 PM |
_ is just a variable name they used, and that whole for blah in blah is a generic for loop |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:07 PM |
Ah, that makes sense, thanks. And for the 'in pairs' part?
#code "Thanks in advance" -- Online |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2016 07:08 PM |
its just a loop that iterates through table
local table1 = {"this","is","a","loop"}
for index, value in pairs(table1) do print(index, value) end
Instance.new("BodyThrust",SenseiWarrior).position = CFrame.new(SenseiWarrior,YourGirlsDMs) |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:10 PM |
Ah, so it's what makes the for repeat.
#code "Thanks for the help. Case closed." -- Online |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2016 07:11 PM |
That's just a function that is called which returns an 'iterator' function which the generic for loop uses to actually iterate.
That sounds confusing, but maybe this'll help
http://www.lua.org/pil/4.3.5.html http://www.lua.org/pil/7.2.html |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 13 Apr 2016 07:11 PM |
It loops through a table
in your example the _ is the index number and the var is the variable, I personally use i,v but you literally can use whatever you want.
Put a bunch of parts and name them differently in ReplicatedStorage and use this script and you will see what it does
for i,v in pairs(game.ReplicatedStorage:GetChildren()) do print(i,v) end |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:13 PM |
That makes sense. So in i,v the i is the number, and v is the variable.
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:17 PM |
Also, why won't this work?
local players=game:GetService("Players") local parent=script.Parent players:GetPlayers(function(p) print(p.Name+" has entered game.") parent.Text = "Players: "..tonumber(p) end)
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2016 07:19 PM |
game.Players.PlayerAdded:connect(function(newPlayer) print(newPlayer.Name) end)
Instance.new("BodyThrust",SenseiWarrior).position = CFrame.new(SenseiWarrior,YourGirlsDMs) |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:27 PM |
Sorry, still doesn't work.
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:29 PM |
Am I lacking a loop?
local players=game:GetService("Players") local parent=script.Parent
while wait() do players:GetPlayers(function(p) print(p.Name+" has entered game.") parent.Text="Players: "..tonumber(p) end) end
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
ausmel105
|
  |
| Joined: 05 Oct 2010 |
| Total Posts: 251 |
|
|
| 13 Apr 2016 07:37 PM |
What SenseiWarrior has given you should work.
game.Players.PlayerAdded:connect(function(newPlayer) print(newPlayer.Name) parent.Text = "Players: "..tostring(#(game.Players:GetChildren())) end)
|
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 13 Apr 2016 07:40 PM |
You dont need one for this
game.Players.PlayerAdded:connect(function(player) print(player.Name.." ".."Has entered the game!") end)
plrs=game.Players:GetPlayers()
script.Parent.Text="Players:".."..#plrs |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:41 PM |
Horray! Finally got results. Thanks for the help.
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 13 Apr 2016 07:41 PM |
Oops a stray quote there
game.Players.PlayerAdded:connect(function(player) print(player.Name.." ".."Has entered the game!") end)
plrs=game.Players:GetPlayers()
script.Parent.Text="Players:"..#plrs |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:42 PM |
Yup I fixed it, works great. Thanks again.
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 07:46 PM |
Just out of curiosity, are hashtags tonumber() things for short?
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 13 Apr 2016 07:47 PM |
| Hashtags are used to get the number of items in the table. |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 13 Apr 2016 08:01 PM |
Ah, alright. Sorry, last question. Why won't this work?
function playerAdded() local plrnum=game.Players:GetPlayers() script.Parent.Text="Players:".." "..#plrnum end
game:GetService("Players").PlayerAdded:connect(playerAdded)
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 13 Apr 2016 08:02 PM |
| Because the function only runs when a new player is added. |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 14 Apr 2016 02:37 PM |
When you join it doesn't register you as a player added? I suppose that makes sense. Thanks for the help.
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 14 Apr 2016 02:48 PM |
| It does, on second thought, that should probably work. Any errors? |
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 14 Apr 2016 02:49 PM |
Nope, but unfortunately, this only sort of works. I just tried getting on with my mobile, and it updated the text on there, but not on my computer. Here's the code.
while wait(1) do local plrs=game.Players:GetPlayers() script.Parent.Text="Players:".." "..#plrs end
#code "Thanks" -- Online |
|
|
| Report Abuse |
|
|
|
| 14 Apr 2016 02:53 PM |
Do you have any code above that in the same script?
Sometimes if you have code above it, it will not work
such as while wait() do
|
|
|
| Report Abuse |
|
|