generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How come my script only moves 1 player?

Previous Thread :: Next Thread 
Infocus is not online. 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 is not online. 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 is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
11 Mar 2013 01:24 AM
How do I fix it qq
Report Abuse
zars15 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
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 is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
11 Mar 2013 06:46 AM
Idk, I just threw this in
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
11 Mar 2013 06:51 AM
As I told, you should rewrite this.
Report Abuse
Infocus is not online. 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
Christbru01 is not online. Christbru01
Joined: 03 Apr 2010
Total Posts: 649
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 is not online. 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 is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
11 Mar 2013 02:06 PM
Thanks, I appreciate it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image