toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 19 May 2013 08:20 AM |
Hello lovely scripting mates, I got a problem I've never had before and after trying multiple things it still doesn't work as it should be (for me then). It's quite simple, I am inside a function loop like this: ------------- while true do function1() function2() function3() function4() end -------------- I am inside function3 now and I've made an return "error" if someone died before he got teleported, when this happens I want to return to function1 but for some reason when I use return function() it will just continue the script like nothing happend. if someone knows what I do wrong or know what to do with this kind of problem please let me know, I will put the script here below so you can get a better picture from it.
the script explained above:
CheckPlayers = game.Players:GetChildren() for i = 1, #CheckPlayers do if CheckPlayers[i].Character.Humanoid ~= nil then if CheckPlayers[i].TeamColor == game.Teams.Lobby.TeamColor then CheckPlayers[i].TeamColor = game.Teams.Runners.TeamColor CheckPlayers[i].Character.Humanoid.WalkSpeed = 0 CheckPlayers[i].Character.Torso.CFrame = Workspace.Entity.MapHolder:findFirstChild(ChosenMap.Value).RunnerSpawn.CFrame + Vector3.new(math.random(-5, 5), 0, math.random(-5, 5)) wait(0.1) else HintText.Value = "No runners found, returning to the beginning.." wait(3) return WaitForPlayers() end end end |
|
|
| Report Abuse |
|
|
toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 19 May 2013 08:38 AM |
| Nobody knows something about return ? |
|
|
| Report Abuse |
|
|
Xheng
|
  |
| Joined: 28 Apr 2013 |
| Total Posts: 158 |
|
|
| 19 May 2013 08:39 AM |
| return is something that is hard to explain though ._. |
|
|
| Report Abuse |
|
|
toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 19 May 2013 09:03 AM |
| Boys I need this to finish mah script |
|
|
| Report Abuse |
|
|
Zomebody
|
  |
| Joined: 01 Jun 2010 |
| Total Posts: 789 |
|
|
| 19 May 2013 09:28 AM |
| Why not just skip function 4? |
|
|
| Report Abuse |
|
|
toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 19 May 2013 10:14 AM |
Because It's for a game, if I skip function 4 then it's not really a game anymore.
|
|
|
| Report Abuse |
|
|
Zomebody
|
  |
| Joined: 01 Jun 2010 |
| Total Posts: 789 |
|
|
| 19 May 2013 10:21 AM |
| No, I mean like: Isn't it possible to make a condition that skips function 4 if someone dies? The script will then start over again at function 1, because of the 'while true do'. |
|
|
| Report Abuse |
|
|
toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 19 May 2013 10:25 AM |
| Hmm ya that's basicly the same thing I want, how would you do that? |
|
|
| Report Abuse |
|
|
lombardo2
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 19 May 2013 10:32 AM |
You can't do that. That's not how return works
function a() b() print("hi") end
function b() print("world") end
a()
It will first print world, then the control flow would return to the place where b was called so it wold print hi.
When you use return in a function, the flow leaves the function and stores the result of the expression so you can read it and assign it to something. |
|
|
| Report Abuse |
|
|
|
| 19 May 2013 10:37 AM |
Try: WaitForPlayers() Instead of: return WaitForPlayers()
If that's the pace you're talking about. Not sure if it'll work. |
|
|
| Report Abuse |
|
|
|
| 19 May 2013 10:41 AM |
That won't return to function one, I am pretty sure it just calls function 1, then it would continue to function 4. Try something like this :
while true do function1() function2() local good = function3() ---return true if you can continue if good then function4() end end
|
|
|
| Report Abuse |
|
|
toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 20 May 2013 05:32 AM |
Thanks but I don't think that will work for me. I have multiple checks like that within function2 and 3, I need to find out someone else. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 May 2013 05:34 AM |
| Quick fix: Pcall each function, so if it errors, it will continue to next function. |
|
|
| Report Abuse |
|
|
toadjesse
|
  |
| Joined: 03 Jun 2008 |
| Total Posts: 5617 |
|
|
| 20 May 2013 08:47 AM |
| @zars, what do you mean with Pcall? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 20 May 2013 08:50 AM |
| Ah... I forgot that you can't pcall with 'wait' in your code. You should make sure to handle if people quit the game. Like, secure it so it doesn't crash when someone quits. |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 20 May 2013 08:52 AM |
"I forgot that you can't pcall with 'wait' in your code."
You can with ypcall() |
|
|
| Report Abuse |
|
|