Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 01:17 AM |
Im making a simple tourney script.. GetPlayers only moved 1 player to 0, 0, 0 No output I put up a message where the problem is. Also, the following codes after the problem wont work.
game.Players.PlayerAdded:connect(function(plyr) plyr.CharacterAdded:connect(function(char) repeat wait() until char
if plyr.Name == "Infocus" then plyr.Chatted:connect(function(msg) if msg == "load/" then
h = Instance.new("Hint", workspace) h.Text = "Loading Battlefield." wait(1) h.Text = "Loading Battlefield.." wait(1) h.Text = "Loading Battlefield..." wait(1) h:Destroy()
field = game.Lighting:findFirstChild("Arena"):Clone() field.Parent = workspace field.Position = Vector3.new(0, 0, 0)
for _, player in pairs(game.Players:GetPlayers()) do if player.Character then player.Character:MoveTo(Vector3.new(0, 0, 0)) --HERE I AM
print("hi")
shin = Instance.new("Hint", game.Workspace) shin.Text = "Let the training begin!" wait(3) shin:Destroy()
print("Hi2")
sword = game.Lighting:findFirstChild("Sword"):Clone() sword.Parent = player.Backpack
print("hi3")
wait(30)
for n, x in pairs (game.Players.GetPlayers()) do o = x.Backpack:findFirstChild("Sword") print("hi4") if o == nil then x:MoveTo(Vector3.new(0, 100, 0)) game.Workspace:findFirstChild("Arena"):Destroy() else return end end end end end end) end end) end)
|
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 01:23 AM |
| You start game for each player. Teleport people and start game only once per command. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 01:26 AM |
| You do stuff to characters in that loop, and then end it. Then continue with gamescript. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 01:45 AM |
Can you help ._.? I'm a bit confused |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 02:25 AM |
| So you have script, but you wasn't sure about stuff you were doing? |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 04:56 AM |
I did, but I'm confused how get players only got one and gave the tool to the only one that was moved. I don't get what you mean by loop the character the. The rest of the code.
What am I supposed to do to the char? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 05:03 AM |
Here, you start a loop here:
for _, player in pairs(game.Players:GetPlayers()) do if player.Character then player.Character:MoveTo(Vector3.new(0, 0, 0))
And directly move on to game script. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 05:40 AM |
so
while wait() do that code end
Or
repeat wait() until ~something~ |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 05:52 AM |
| ...First you have to understand what you want to do. Use functions to organize it more. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 05:59 AM |
| Didnt really think this would cause much trouble for me.. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 06:08 AM |
| Just try to rewrite, and think logically what you are trying to do in each line of script. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 06:17 AM |
But I am on the right track right?
Basically, once I chat, it teleports all players to 0,0,0 then clones the swords. 30 seconds later, the script checks if you still have a sword, if you do, it removes it and teleports you back. |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 06:45 AM |
| Why is the whole function triggered from playeradded? It's like whenever a new player joins they will add another game to your place, so with 3 players you might have 3 games running at once. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 06:51 AM |
| As I told, you should rewrite this. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 11 Mar 2013 07:14 AM |
Can you give me an outline of how I should rewrite it? People are saying dont use PlayerAdded or something |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 07:43 AM |
It is doing this because you did not close the loop before putting the wait()s and such, so it goes through that entire run, then does it again for the next player, and again, and again, until all the players are done...
The for _,player in pairs(game.Players:GetChildren()) do is the same as having for i=1, #game.Players:GetChildren() do so instead of player, it'd be game.Players:GetChildren()[i], which is why it is better to use pairs, it just makes it look cleaner. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 11 Mar 2013 08:34 AM |
Schematic, of how I'd do it:
-Game function
-PlayerAdded --If player is admin or stuff ---Chatted ----If message = "play/" and not gameRunning -----Do: Game function
You should draw algorithms, if you are confused on how to organize your script. |
|
|
| Report Abuse |
|
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
| |
|