I created a script. It worked the couple of first times, but then it kept breaking. Anyone mind helping?
Here's the script -
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local mouse = game.Players.LocalPlayer:GetMouse() |
03 | local infogui = game.Players.LocalPlayer.PlayerGui:WaitForChild( "InfoUI" ) |
04 |
05 |
06 | function hover() |
07 | if mouse.Target.Parent.Name = = "Item1" then |
08 | infogui.INFO 1. Visible = true |
09 | infogui.INFO 1. Position = UDim 2. new( 0 , mouse.X, 0 , mouse.Y) |
10 | else |
11 | infogui.INFO 1. Visible = false |
12 | end |
13 | end |
14 |
15 | mouse.Move:connect(hover) |
Thanks! :)
When I tested your code I recieved the error: Players.TreacherousTale.Backpack.LocalScript:8: attempt to index field 'Target' (a nil value)
To fix this, you must check whether mouse.Target = true
.
Furthermore, when the mouse hovers from Item1
to nil (the skybox), the infogui
doesn't disappear. To fix this I checked whether mouse.Target = nil
, and if it did then you'd set infogui.INFO1.Visible
to false
.
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local mouse = game.Players.LocalPlayer:GetMouse() |
03 | local infogui = game.Players.LocalPlayer.PlayerGui:WaitForChild( "InfoUI" ) |
04 |
05 | function hover() |
06 | if mouse.Target then -- Check if there is actually a Target |
07 | if mouse.Target.Parent.Name = = "Item1" then |
08 | infogui.INFO 1. Visible = true |
09 | infogui.INFO 1. Position = UDim 2. new( 0 , mouse.X, 0 , mouse.Y) |
10 | else |
11 | infogui.INFO 1. Visible = false |
12 | end |
13 |
14 | else |
15 | infogui.INFO 1. Visible = false -- If there isn't a target, make the infoUI invisible |
16 |
17 | end |
18 | end |
19 |
20 | mouse.Move:connect(hover) |
You weren't exactly clear on what the problem was so I tried my best with what I was working with. I hope I helped!