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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 24 Feb 2009 |
| Total Posts: 58 |
|
|
| 14 Jul 2013 10:55 AM |
| thanks anyway, i figured it. |
|
|
| Report Abuse |
|
|