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 » Scripters
Home Search
 

Re: Why doesn't it disconnect the function?

Previous Thread :: Next Thread 
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:12 PM
repeat wait() until game.Players.NumPlayers == 1
if game.Players.NumPlayers == 1 then
round:Disconnect()
mode.Value = "Waiting for Players"
time.Value = 1
for _, player in ipairs(game.Players:GetChildren()) do
local spawns = game.Workspace.Spawns:GetChildren()
player.Character.HumanoidRootPart.CFrame = spawns[math.random(#spawns)].CFrame+Vector3.new(0,5,0)
map:Destroy()
end
end


ATR'er since 2013.
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:31 PM
bump


ATR'er since 2013.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
29 Mar 2017 08:34 PM
Show script with the event
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:39 PM
I don't want to show the full event but its

local round = function()
-- then it changes a bunch of string values, teleports players, choses a map, spawns it


ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Mar 2017 08:39 PM
So it's not an event then...?


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:40 PM
full code*


ATR'er since 2013.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
29 Mar 2017 08:40 PM
Try this

local round round = function()

Then obvs youd do round:connect/round:disconnect()
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:41 PM
There is no remoteevent connected to this btw


ATR'er since 2013.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
29 Mar 2017 08:41 PM
It doesnt work if it aint an event

Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
29 Mar 2017 08:42 PM
I meant event as in .Touched .Chatted etc
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:42 PM
do you count while true do to be an event? lol

It's a function, and it loops through intermission, map selecting, being on the map, then ending and going back to intermission.

If there is only one player, then I want that to stop, but resume at intermission when it reaches 2 players again


ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Mar 2017 08:43 PM
"local round = function()"

Also, don't do that. It's bad practice, because if you need to call a function inside itself, it won't be defined at the time that the code is compiled, resulting in an error.

Either use:

local round
round = function()
end

Or:

local function round()
end

They're both exactly the same thing; the first example I posted is what they both ultimately expand to though.


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:45 PM
Okay, I changed it to that, sub.


ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Mar 2017 08:47 PM
For my suggestion about the actual thing wrong with your code, I'd suggest connecting a function to the PlayerRemoving event and if NumPlayers is less than 2 then stop the round.


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Mar 2017 08:47 PM
(and of course disconnect the function from the event when the round ends)


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
29 Mar 2017 08:50 PM
Like this?
game.Players.PlayerRemoving:connect(function(plr)
if game.Players.NumPlayers == 1 then
round:Disconnect()
end
end)

local round
round = game.Players.PlayerAdded:connect(function()

--- loop and stuff




ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Mar 2017 08:52 PM
Something like:

local players = game:GetService("Players")
local connection

local function stopRound()
-- stop the round
end

local connection = players.PlayerRemoving:Connect(function()
if players.NumPlayers <= 1 then
-- call the stop round function (filtered)
connection:Disconnect()
end
end)


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Mar 2017 08:56 PM
Remove the second `local` before the `connection` variable.


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
29 Mar 2017 08:57 PM
if its a while loop you mean to use break


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
30 Mar 2017 08:50 AM
How would I break the loop if I only want to do it when there is one player.


ATR'er since 2013.
Report Abuse
Atavis is not online. Atavis
Joined: 10 Apr 2012
Total Posts: 1463
30 Mar 2017 08:50 AM
break;

idk this post is tl;dr


120,310 slices of pizza and counting!
Report Abuse
Lurching_Spark is not online. Lurching_Spark
Joined: 01 Oct 2016
Total Posts: 255
30 Mar 2017 10:47 AM
You could check how many players there are every time the loop runs. Or else you could just set a boolean for the loop to check, using your event script.

while true do
if bool == true then
break
end
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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