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: :disconnect() is deprecated?

Previous Thread :: Next Thread 
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
31 Oct 2014 04:23 PM
I was hoping to use it, it would make my script a bit easer then using global variables and repeat loops.

Is there any other way of doing it?
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
31 Oct 2014 04:24 PM
It's not deprecated? Lol?
Report Abuse
ToxicDominator is not online. ToxicDominator
Joined: 24 Oct 2013
Total Posts: 8373
31 Oct 2014 04:24 PM
RBXScriptConnection:disconnect()
Report Abuse
ToxicDominator is not online. ToxicDominator
Joined: 24 Oct 2013
Total Posts: 8373
31 Oct 2014 04:24 PM
FedoraKid, yes it is
returns an error message
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
31 Oct 2014 04:25 PM
WELL I GOT AN ERROR SAYING IT WAS!!!
Sorry, capslock.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
31 Oct 2014 04:26 PM
Seriously? Damnit...why would it be deprecated?

Honestly I was thinking of using it just yesterday, but I rather figured I could just run checks in the touched event instead of taking the bother to disconnect...

Disconnect could come in handy though.
Report Abuse
ToxicDominator is not online. ToxicDominator
Joined: 24 Oct 2013
Total Posts: 8373
31 Oct 2014 04:27 PM
It's still usable in a different way
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
31 Oct 2014 04:27 PM
Oh,well thanks.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
31 Oct 2014 04:27 PM
Yeah I could still use it, but It's faster just running checks in the event than :disconnect..
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
31 Oct 2014 04:30 PM
:disconnect() is still easier.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
31 Oct 2014 04:45 PM
Not in my opinion, for example

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") and script.Parent.Transparency ~= 1 then
--stuff
end
end)

While for example in disconnect, you'd have to disconnect it when, let's say if the brick is invisible, while I could just do a check like this.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
31 Oct 2014 05:52 PM
Why would someone ever want to disconnect an event :O?
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
31 Oct 2014 05:59 PM
@cntkillme

Don't know, but I guess there are reasons.
I know ROBLOX uses it in their animation script, for example.

~The herp lerped a derp~
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
05 Nov 2014 06:58 PM
This is why you would want to use it.

function on2D ()
cam.CameraType=Enum.CameraType.Scriptable
while true do
cam:Interpolate(CFrame.new(player.Character.Torso.Position)* CFrame.new(-20,0,2), player.Character.Torso.CFrame, .5)
wait(.6)
end
end
function on3D()
cam.CameraType=Enum.CameraType.Follow
end
dem=workspace.PlayersDemChanger:WaitForChild(player.Name.."DemChanger2")
dem.OnClientEvent:connect(on2D)
dem2=workspace.PlayersDemChanger:WaitForChild(player.Name.."DemChanger3")
dem.OnClientEvent:connect(on3D)
dem.OnClientEvent:disconnect(on2D)
Report Abuse
IthacaMedia is not online. IthacaMedia
Joined: 25 Jan 2014
Total Posts: 1337
05 Nov 2014 07:49 PM
Oh cool you can disconnect Remote/BindableFunctions! xD.

Anyway, I'm kind of surprised that it's deprecated, maybe its due to some bug or something.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
05 Nov 2014 08:06 PM
Its only deprecated/broken like this

script.Parent.Touched:connect(function(object)
print("1")
script.Parent.TouchInterest:disconnect()
end)


do this

local self;
self = script.Parent.Touched:connect(function(object)
print("1")
self:disconnect()
end)
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
08 Nov 2014 01:53 PM
Ah, cool.
Report Abuse
einsteinK is not online. einsteinK
Joined: 22 May 2011
Total Posts: 1015
08 Nov 2014 01:58 PM
More or less what 128GB said.

A long time ago, you could do 'event:disconnect()' to disconnect all connections.
Now, connecting to an event returns a connection:
local connection = event:connect(handlerFunction)
You can then disconnect that connection with:
connection:disconnect()

A thing a lot of people try, is this:
local con = event:connect(function()
con:disconnect()
dostuff()
end)

That'll error, saying that 'global con is nil'
That's because in reality, the function is created before 'con' is declared.

A simple fix is just doing this:
local con con = event:connect(function()
con:disconnect()
dostuff()
end)
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
08 Nov 2014 08:51 PM
'local con con = event:connect(function()'

Thats the same thing as this but on 1 line

local self;
self = script.Parent.Touched:connect(function(object)
print("1")
self:disconnect()
end)'
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
11 Nov 2014 08:26 AM
Oh, does the event have to be running in order to disconnect it?
I guess that makes sense.
Report Abuse
inapt is not online. inapt
Joined: 04 Oct 2008
Total Posts: 11666
11 Nov 2014 10:30 AM
not depreciated...?

local event;
event = part.Touched:connect(function(hit)
print(hit.Name)
event:disconnect()
end)


-ForeverDev
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
11 Nov 2014 03:39 PM
No it doesn't have to be running
local event = workspace.ChildAdded:connect(function(child)
print(child.Name)
end)
event:disconnect()
Report Abuse
protectiveEBob is not online. protectiveEBob
Joined: 09 Jul 2012
Total Posts: 1297
12 Nov 2014 07:26 AM
Okay, so you can only disconnect an event if you set as a variable the event which is connected to a function? I have a feeling that it would still error.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
12 Nov 2014 11:38 AM
It wouldn't error

And no but reasonable you would always set a variable to it and disconnect it later

workspace.ChildAdded:connect(function(child)
print(child.Name)
end):disconnect()

Works, but is pointless
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
12 Nov 2014 11:49 AM
If you want something only to run once, then wrap it into a coroutine and use :wait instead hehe
If you need it to disconnect under specific conditions, there are always better ways of doing it but 128's method works just fine.
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