How would I go about making a script that, when the player hovers their mouse over a part, a UI with text on it becomes visible to whoever hovered their mouse over it?
I'm not asking for someone to write me a script as I wont learn anything, I just want to know how to go about it or any useful events / functions I can use to accomplish my goal.
Thanks in advance
Well there are a lot of ways to accomplish this Mouse.Move
Mouse.Target
and MouseHoverEnter
MouseHoverLeave
MouseHoverEnter and MouseHoverLeave are 2 events of the ClickDetector what I do when I want a UI textlabel or any UIobject to appear I put a localscript inside of StarterGui
and the ClickDetector inside of the part and I make the localscript go through the PlayerGui
which is what we are gonna use cause as you said you want it to appear on the screen of the player who hovered over it so We are gonna access PlayerGui by game.Players.LocalPlayer.PlayerGui.guinamehere
then inside of the localscript we are gonna write a MouseHoverEnter function that makes the UI visible then we are gonna write another function in the same script with MouseHoverLeave which will make the UI visible = false. Then in the end we are gonna connect the functions to the ClickDetector like game.Workspace.Part.ClickDetector.MouseHoverEnter:connect(HoverEnter)
and game.Workspace.Part.ClickDetector.MouseHoverLeave:connect(HoverLeave)
I've left some links down below about this.
http://wiki.roblox.com/index.php?title=API:Class/ClickDetector/MouseHoverEnter http://wiki.roblox.com/index.php?title=API:Class/ClickDetector/MouseHoverLeave http://wiki.roblox.com/index.php?title=API:Class/PlayerGui
I hope it helped if it did then make sure to accept answer!
Some important things are Mouse.Move(event) and Mouse.Target(object).
Mouse.Move is an event fired whenever the mouse moves. Mouse.Target is the object the mouse is hovering over. Combining these two you can make a function that fires when the mouse moves, and then checks if mouse.target is the select part. If it is you should display the gui. If it isn't you should hide it. Also keep in mind to check if mouse.target isn't nil, so that it doesn't throw errors en masse.
Good luck!
I made this simple script that should do it for you!
I do suggest putting the local script in startergui or the gui
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local PartName = "Part" -- Put the part name here local Part = game.Workspace:FindFirstChild(PartName) -- replace the game.Workspace with the location of the part local Gui = Player.PlayerGui.ScreenGui -- Replace this with the location of the Gui you want to change Mouse.Move:connect(function() if Mouse.Target == Part then Gui.Frame.Visible = true end end)