Malcolt3
|
  |
| Joined: 17 Dec 2009 |
| Total Posts: 11442 |
|
|
| 09 Mar 2014 11:24 AM |
Are any efficient ways to either
1) access the player mouse from a script that isn't local
or
2) easily access _G from a localscript |
|
|
| Report Abuse |
|
|
| |
|
|
| 09 Mar 2014 11:26 AM |
1.use a tool.Equipped event,and you can easily get the mouse 2._G can not be accessed from a localscript |
|
|
| Report Abuse |
|
|
Malcolt3
|
  |
| Joined: 17 Dec 2009 |
| Total Posts: 11442 |
|
|
| 09 Mar 2014 12:05 PM |
| @island So I managed to get the mouse with a tool and set it to a global variable, but none of the events ever fire when I try to use it in another script. For example, I have a KeyDown event that's set to do something, but nothing ever happens. |
|
|
| Report Abuse |
|
|
| |
|
Malcolt3
|
  |
| Joined: 17 Dec 2009 |
| Total Posts: 11442 |
|
|
| 09 Mar 2014 12:16 PM |
Here's the tool script:
repeat wait() until script.Parent.Parent ~= game.StarterPack
tool = script.Parent
h = Instance.new('Hint', Workspace) h.Text = '1'
tool.Equipped:connect(function(m) h.Text = '2' _G.Mouse = m h.Text = '3' tool:Destroy() h.Text = '4' end)
And here's the script that tries to use the mouse:
gui = script.Parent.Parent repeat wait() until gui.Parent ~= game.StarterGui
player = gui.Parent.Parent
mouse = nil tool = player.Backpack.Tool tool.Equipped:connect(function(m) mouse = m end)
repeat wait() until mouse
mouse.KeyDown:connect(function(key) if key == 'b' then if tray_backpack.Visible == true then closeall() elseif tray_backpack.Visible == false then closeall() tray_backpack.Visible = true end end end) |
|
|
| Report Abuse |
|
|
Malcolt3
|
  |
| Joined: 17 Dec 2009 |
| Total Posts: 11442 |
|
|
| 09 Mar 2014 12:17 PM |
| All of the functions in the second script work; it seems like the KeyDown event isn't activated. |
|
|
| Report Abuse |
|
|
| |
|
Malcolt3
|
  |
| Joined: 17 Dec 2009 |
| Total Posts: 11442 |
|
|
| 09 Mar 2014 12:35 PM |
| @Dueling Switching _G.Mouse to _G["Mouse"] doesn't do anything. |
|
|
| Report Abuse |
|
|