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()?

Previous Thread :: Next Thread 
Joeza8901 is not online. Joeza8901
Joined: 24 Feb 2009
Total Posts: 58
14 Jul 2013 10:05 AM
can someone tell me whats wrong with this script?
the first Equipped function is work pretty fine but the Unequipped function isn't working
if someone can help me fix it. thanks!
ps. this one the error said "x is nil value"..
and I've tried Mouse.Move:disconnect(function() but error said "disconnect() has been deprecated. Use connection object returned by connect()"

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local tool=script.Parent

tool.Equipped:connect(function()
local x = Mouse.Move:connect(function()
if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Anvil" then
print ("working")
else
print ("cannot find object")
end
end )
end)

tool.Unequipped:connect(function()
x:disconnect(function()
end)
end)
Report Abuse
1cooldude361 is not online. 1cooldude361
Joined: 13 Mar 2010
Total Posts: 4403
14 Jul 2013 10:20 AM
I believe when a variable is within a function, and you close the function, then the variable can't be used anywhere else. You would have to redefine x, I think.

"IT'S A CONSPIRACY!"
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
14 Jul 2013 10:22 AM
I don't think it's really necessary, but you could do:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local tool=script.Parent
local Equipped = false

tool.Equipped:connect(function()
Equipped = true
Mouse.Move:connect(function()
if not Equipped then return end
if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Anvil" then
print ("working")
else
print ("cannot find object")
end
end)
end)
tool.Unequipped:connect(function()
Equipped = false
end)
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
14 Jul 2013 10:24 AM
u r not using disconnect the way the Wiki described using disconnect.

Go look it up, but it was something like this:

local x = nil -- connection = nil, in the Wiki. So like the guy said make your reference to connection global.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local tool=script.Parent

tool.Equipped:connect(function()
x = Mouse.Move:connect(function()
if Mouse.Target ~= nil and Mouse.Target.Parent.Name == "Anvil" then
print ("working")
else
print ("cannot find object")
end
end )
end)

tool.Unequipped:connect(function()
x:disconnect(function()
end)
end)
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
14 Jul 2013 10:26 AM
tool.Unequipped:connect(function()
x:disconnect(function()
end)
end)

doesn't look right either for a disconnect. Where r u getting this stuff? Copy the Wiki.

Report Abuse
Joeza8901 is not online. Joeza8901
Joined: 24 Feb 2009
Total Posts: 58
14 Jul 2013 10:42 AM
Copy wiki still not working and I've been there before asking here.
Report Abuse
Joeza8901 is not online. Joeza8901
Joined: 24 Feb 2009
Total Posts: 58
14 Jul 2013 10:55 AM
thanks anyway, i figured 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