I wanted to know two things. One, Is it possible for roblox to detect your mouse thats hovering. So like I am just looking at the block. and two is it possible to use a billboardGui to display that you should hit a key or something so like I am looking at a door and then hit R and the door opens. Main question though is can it detect mouses that are hovering over objects.
Mouse Hover detection/Key hit?
1 answer
Yes you can, and it's actually quite easy.
There is a property of mouse called Target that is equal to the object in the Workspace that the mouse is currently pointed at. Knowing this, we can write a script that checks to see what the mouse is pointing at each time the mouse is moved. If it is pointed at the door, we will call a function to display the billboard GUI. However, we will have to remove the billboard GUI each time the mouse is move or else they will never disappear.
You can go about this in two ways, either clone and destroy the GUI or simple set the visible property of the GUI objects depending on if it should be shown or not. These examples should be run in local script
####Example 1:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local door = game.Workspace.Door
local gui = LOCATION_OF_BILLBOARD_GUI
mouse.Move:connect(function)
if mouse.Target and mouse.Target == door then
gui.Frame.Visible = true
else
gui.Frame.Visible = false
end
end)
####Example 2:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local door = game.Workspace.Door
local gui = LOCATION_OF_BILLBOARD_GUI
local copy
mouse.Move:connect(function)
if copy then
copy:Destory()
end
if mouse.Target and mouse.Target == door then
copy = gui:Clone()
copy.Parent = DESIRED_LOCATION
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
