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: How to? Hover mouse

Previous Thread :: Next Thread 
xFortunato is not online. xFortunato
Joined: 25 Nov 2010
Total Posts: 865
21 Sep 2011 02:01 PM
I want a text box in the player's gui to change based on what the player's mouse is hovering over. How do I do this? (General outline, not all the exact code)

Currently I'm trying
- StringValue in brick named MouseTarget
- script under textbox in the gui that updates the textbox's text when the player's 'MouseTarget' stat (located as a string value at Player.stat.MouseTarget) changes
-Here's where I get stuck: It worked when I used mouse.Move() and mouse.Idle() under a tool's script, but that's a shaky way to do it, so how can I use mouse.Changed() with Target as a property to update the player's stat?

Here's all the code

------CHILD OF TOOL
function findTarget(part)
local e = part:findFirstChild("MouseTarget")
if e ~= nil then
return part.MouseTarget
else
return nil
end
end


function onMouseHover(mouse)

local target = mouse.Target

while true do
wait(1)
if target ~= nil then

local p = nil
p = findTarget(target)

if p ~= nil then

script.Parent.Parent.Parent.stats.MouseTarget.Value = target.MouseTarget.Value
elseif p == nil then
script.Parent.Parent.Parent.stats.MouseTarget.Value = "-None-"
end
end
end
end


function onSelected(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Move():connect(function() onMouseHover(mouse) end)
mouse.Idle():connect(function() onMouseHover(mouse) end)

end


tool.Selected:connect(onSelected)



--CHILD OF SCREENGUI.etc.etc.TEXTLABEL

local label = script.Parent

wait(1)

local stat = script.Parent.Parent.Parent.Parent.Parent.Parent.stats.MouseTarget

stat.Changed:connect(function()
local newVal = stat.Value
label.Text = newVal
end)


And of course Player.stats.MouseTarget is created upon entry and the target brick has a stringvalue with name "MouseTarget"
Report Abuse
myrco919 is not online. myrco919
Joined: 12 Jun 2009
Total Posts: 13241
21 Sep 2011 02:19 PM
[ Content Deleted ]
Report Abuse
xFortunato is not online. xFortunato
Joined: 25 Nov 2010
Total Posts: 865
21 Sep 2011 02:36 PM
This isn't for a GUI...
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
21 Sep 2011 02:37 PM
you could try the Idle and Move event of the mouse. the Idle fires when your mouse isn't moving and the Move event fires when your mouse moves. i just learned about them i few minutes ago :P
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
21 Sep 2011 02:52 PM
Here :P xD


function onMouseHover(mouse)
local target = mouse.Target

while true do
wait(1)
if mouse.Target ~= nil then

local p = nil
p = findTarget(target)

if p ~= nil then

script.Parent.Parent.Parent.stats.MouseTarget.Value = mouse.Target.MouseTarget.Value
elseif p == nil then
script.Parent.Parent.Parent.stats.MouseTarget.Value = "-None-"
end
end
end
end


function onSelected(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Move:connect(function() onMouseHover(mouse) end)
mouse.Idle:connect(function() onMouseHover(mouse) end)

end
Report Abuse
xFortunato is not online. xFortunato
Joined: 25 Nov 2010
Total Posts: 865
21 Sep 2011 02:59 PM
Miro, MrGames:
Are you two serious? You just gave me back the code I already have

function onSelected(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Move():connect(function() onMouseHover(mouse) end)
mouse.Idle():connect(function() onMouseHover(mouse) end)

the ()'s are typos...
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
21 Sep 2011 02:59 PM
lol, i just failed there. i didn't see that XD
Report Abuse
Miro034 is not online. Miro034
Joined: 07 Oct 2009
Total Posts: 6568
21 Sep 2011 03:00 PM
same here kid...
Report Abuse
xFortunato is not online. xFortunato
Joined: 25 Nov 2010
Total Posts: 865
21 Sep 2011 03:43 PM
So does anybody know how to do this?
The problem is that the current function to detect mouse moving and idling causes a 1 second delay before changing the text. I would like it to be instant but removing the wait makes the while loop crash the program.
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