|
| 21 Sep 2011 12:20 PM |
i've been pushing it off for months, but today i finally decided to learn :P
function mouse(m) print("clicked") end script.Parent.Selected:connect(function(m) m.Button1Down:connect(function() mouse(m) end) print("Selected") end)
script.Parent.Deselected:connect(function() print("Deselected") end)
|
|
|
| Report Abuse |
|
|
Fl0x
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 5169 |
|
| |
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 21 Sep 2011 12:23 PM |
Actually, you can do it a bit differently. :o
script.Parent.Selected:connect(function(m) print("Selected") m.Button1Down:connect(function() print("clicked") end) end)
The whole moving the mouse to another function is not entirely necessary. :3
Good job, none-the-less! Keep up with the knowledge! |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 12:27 PM |
| :o thats a little more simple, i think i'll use that way, and the way you find what object you click is: 'm.Target' right? If i wanted to find the name i could just do: 'm.Target.Name' ? |
|
|
| Report Abuse |
|
|
Fl0x
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 5169 |
|
|
| 21 Sep 2011 12:28 PM |
| m.Target is the part you are hovering at, not clicking at. |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 12:30 PM |
| :o ok, so how would i find the object which is clicked? |
|
|
| Report Abuse |
|
|
Fl0x
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 5169 |
|
|
| 21 Sep 2011 12:31 PM |
| Check mouse.Target when mouse.Button1Down is fired. |
|
|
| Report Abuse |
|
|
| |
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 21 Sep 2011 12:38 PM |
Mouse.Hit works, too. It returns the position that you were pointing. |
|
|
| Report Abuse |
|
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 21 Sep 2011 12:39 PM |
Mouse.Target = Object Mouse.Hit = Position |
|
|
| Report Abuse |
|
|
Miro034
|
  |
| Joined: 07 Oct 2009 |
| Total Posts: 6568 |
|
|
| 21 Sep 2011 12:41 PM |
| ohnow I get it...Thx grim...:D |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 12:42 PM |
| thanks for the help, now i'm going to try to make something a little more complicated :3 |
|
|
| Report Abuse |
|
|
Fl0x
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 5169 |
|
|
| 21 Sep 2011 12:44 PM |
http://wiki.roblox.com/index.php/RBX.lua.Mouse_(Object) For more functions,properties and events. |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 12:50 PM |
heres a quick script i made for my game, but for some reason the .Selected event isn't firing :\
script.Parent.Selected:connect(function(m) local player = game.Players.LocalPlayer print("Selected")
m.Button1Down:connect(function() local targ = m.Target print("click")
if targ ~= nil then print(targ.Name)
if targ.Name == "WaterSource" then local mag = (targ.Position - game.Workspace.WaterSource.Position).magnitude
if mag <= 5 then player.Hunger.Frame.Tbar1.Size = UDim2.new(0.4, 0, 0.3, 0) player.Character.Humanoid.Health = 100 end end end end) end)
script.Parent.Deselected:connect(function() print("Deselected") end)
|
|
|
| Report Abuse |
|
|
Fl0x
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 5169 |
|
|
| 21 Sep 2011 12:52 PM |
Make sure it's a; Localscript and inside of a Hopperbin |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 12:52 PM |
| yup, its a local script and its in a hopperbin |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 01:00 PM |
i did notice a minor error, but its still not the source of the problem
local mag = (player.Character.Torso.Position - targ.Position).magnitude |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2011 01:02 PM |
| whaaaaaat? i changed that exact line ^ and it fixed it :O |
|
|
| Report Abuse |
|
|