|
| 23 Jul 2015 09:21 PM |
I need help understanding how to use this function.
In my game, I am having a map with spawns in it appear, then removing the spawns in the lobby and trying to run through all the players and do "v:LoadCharacter()" However, this isn't working because I have no idea how to use it.
P.S. if there is a better way to spawn the players on the map, telling me would be greatly appreciated. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 23 Jul 2015 09:22 PM |
That should work. Needs to be a serverscript
for i,v in next, game.Players:GetPlayers() do v:LoadCharacter() end
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 01:00 PM |
Does that mean I need to put the script into "ServerScriptService" instead of Workspace? Plus I
did "_, v in pairs (game.Players:GetChildren()) do v:LoadCharacter() end
does that make a difference? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2015 01:04 PM |
No it can be in workspace
Did you actually put the quote in the script? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 24 Jul 2015 01:05 PM |
keep the i and use in next, its more efficient and cleaner looking code. You can have the script in workspace or ServerScriptStorage. SSS is just more secure so I would suggest using that.
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2015 01:12 PM |
No, use pairs if you want. TimeTicks is under the assumption that next > pairs when it's not. The problem was that you forgot the "for" keyword.
for _, v in pairs (game.Players:GetPlayers()) do v:LoadCharacter() end |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 24 Jul 2015 01:14 PM |
@cnt, its not an assumption. It's a fact. Its cleaner looking code. End of story. Obv you don't know what that means.
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Jul 2015 01:16 PM |
I was referring to it being more 'efficient'.
But more to the point, 'clean code' is relative. People say me putting semi-colons at the end of statements is ugly but I think it's fine. _, v might look better than i, v to someone else, it's not fact, it's your own opinion. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 01:30 PM |
No, I didn't put that quotation and I still can't get it to work, play solo or with start server. I'm new to this so I'll just put my script here and you can help that way:
maps = game.ServerStorage.Maps:GetChildren()
h = Instance.new("Hint", game.workspace)
allPlayers = game.Players:GetChildren()
ls = game.ServerStorage.LobbySpawns:Clone()
while true do if game.Players.NumPlayers > 0 then h.Text = "Choosing a map..." wait(3) ranGame = math.random(1, #maps) pickedMap = maps[ranGame] h.Text = pickedMap.Name.." was chosen!" wait(3) pickedMapClone = pickedMap:Clone() pickedMapClone.Parent = game.Workspace game.Workspace.LobbySpawns:destroy() wait() for _, v in pairs (allPlayers) do v:LoadCharacter() end for i = 10, 1, -1 do h.Text = i.." seconds remaining!" wait(1) end h.Text = "Round over!" pickedMapClone:destroy() ls.Parent = game.Workspace wait() for _, v in pairs (allPlayers) do v:LoadCharacter() end wait(5) else h.Text = "This game needs at least 2 players to start!" wait() end end |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 01:38 PM |
| Your script will break if a player leaves when it's starting a match. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 03:07 PM |
| Not the problem right now. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 05:51 PM |
| Bump, I really don't know why this won't work! |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 24 Jul 2015 07:41 PM |
Because you are editing a free modeled minigame script. Lold
"Talk is cheap. Show me the code." - Linus Torvalds |
|
|
| Report Abuse |
|
|
Darkenus
|
  |
| Joined: 17 Jul 2014 |
| Total Posts: 1997 |
|
|
| 24 Jul 2015 08:21 PM |
| I have to agree with timeticks with using next instead of pairs. It is "faster". Even I have gone into the habit of using next. |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 08:59 PM |
It's not a free modeled minigames script, I was watching peaspods tutorials and I made my own, I can't help it if I was making it as basic as possible and I can't get the LoadCharacter() to work. You don't have to be so rude.
What's the difference between in pairs and next? I didn't even know it was a thing. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 Jul 2015 03:50 AM |
'I have to agree with timeticks with using next instead of pairs. It is "faster". Even I have gone into the habit of using next.' Stop, people who say that have no idea how pairs or next works. For a case as this, using a numerical for loop would be ~2x faster than pairs/next and the only reason next is 'faster' (when it's really not) is because pairs is called ONCE, and then next is returned.
The difference between pairs and next is much less significant than numerical for loops vs next/pairs for arrays. |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2015 12:19 PM |
| Well I found out why it wouldn't work anyways. Someone told me in-game that you have to disable :CharacterAutoLoad() before you can use :LoadCharacter() |
|
|
| Report Abuse |
|
|
Darkenus
|
  |
| Joined: 17 Jul 2014 |
| Total Posts: 1997 |
|
|
| 25 Jul 2015 05:30 PM |
| @cnt Pairs will call next, so why not call next directly? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 26 Jul 2015 06:07 AM |
| Because pairs doesn't call next, it returns next. There is almost no point, if a single function call is so important, you are much better of using a numerical for loop. |
|
|
| Report Abuse |
|
|
|
| 26 Jul 2015 06:10 AM |
What tricks me is why they are both here? I use numerical for loops for all my looping already though.
Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784 |
|
|
| Report Abuse |
|
|