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: Why does this script only work once?

Previous Thread :: Next Thread 
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 02:49 PM

local maps = game.Lighting.Maps
local Text = "You need atleast 2 Players to play the game"
while true do

if Game.Players.NumPlayers <= 1 then
local mpd = Instance.new("Message", workspace)
for i = 1,#Text do
wait(0.1)
mpd.Text = (Text:sub(1, i))


end

repeat wait(0.1) until Game.Players.NumPlayers > 1
mpd:Destroy()

for _,map in pairs (maps:GetChildren()) do
local n = Instance.new("Message", workspace)
n.Text = "The next map is "..map.Name
wait(2)
n:Destroy()
for i,v in pairs(game.Players:GetPlayers()) do
wait()
local m = map:Clone()
v.Character.Torso.CFrame = CFrame.new(307, 21, -185) --Bring players to the game.
m.Parent = game.Workspace
end
wait(10)
for i,v in pairs(game.Players:GetPlayers()) do
local player = v
local m = map:Clone()
v.Character.Torso.CFrame = CFrame.new(275, 219.6, -44) --Bring players to the game.
m.Parent = game.Workspace
wait(2)
m:Destroy()
end

end
end
end
Report Abuse
kinglan is not online. kinglan
Joined: 25 Mar 2010
Total Posts: 420
16 Feb 2014 02:51 PM
Does it have a loop or a repeat?
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 02:56 PM
It says while true do
Report Abuse
kinglan is not online. kinglan
Joined: 25 Mar 2010
Total Posts: 420
16 Feb 2014 03:01 PM
Ok, so? what does that have to do with it?
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 03:05 PM
You asked if there was a loop and I said there's a while true do loop as you can see in the script...
Report Abuse
Gorake is not online. Gorake
Joined: 10 Feb 2014
Total Posts: 219
16 Feb 2014 03:09 PM
Because, look at the indented version of your script: pastebin/pH7U4yXz

The if statement which checks to see if there's only 1 player happens EVERY loop. This means that the loop will only run again if there's 1 player in the game, and then it will wait for 2 again, and so on.

Here's more logic-tight setup: pastebin/aR8AKwu2
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 03:12 PM
@Gor, it's suppose to have 2 players in the game to run...?
Report Abuse
Gorake is not online. Gorake
Joined: 10 Feb 2014
Total Posts: 219
16 Feb 2014 03:15 PM
Yes but what you're doing is this:

-Is there only 1 player in game?
--Good, wait until there are 2 people
---OK, now do the map thing
-NOW is there only 1 player in game?
--Nope, there's 2, better wait until there's just 1
--1 person left, now wait until there's 2 people again
---OK, now do the map thing

Over and over, you see?
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 03:17 PM
Wait, why does it ask if there's 1 player and dosn't run if there's 2? Didn't I clearly say if there's 1 or less dont run it? and run it if thers more?
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 03:20 PM
Bump
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 03:23 PM
And how would I just make it ask if there's 2 players, then go?
Report Abuse
Gorake is not online. Gorake
Joined: 10 Feb 2014
Total Posts: 219
16 Feb 2014 03:26 PM
Did you even look at the two pastebins I posted? Put (dot)com between the n and the / to see them. I answered both those questions in my first post.

Basically, it's waiting for 1 player only because you put the check for more than 1 player INSIDE of the conditional for just 1 player. Look at the indentation on the first pastebin.

I fixed it in the second pastebin.
Report Abuse
thetacah is not online. thetacah
Joined: 18 Jan 2013
Total Posts: 16026
16 Feb 2014 03:29 PM
Oh, testing now. Need another player though:D
Report Abuse
Gorake is not online. Gorake
Joined: 10 Feb 2014
Total Posts: 219
16 Feb 2014 03:35 PM
pastebin/g85Y65N4
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