I created a script. It worked the couple of first times, but then it kept breaking. Anyone mind helping?
Here's the script -
local UserInputService = game:GetService("UserInputService") local mouse = game.Players.LocalPlayer:GetMouse() local infogui = game.Players.LocalPlayer.PlayerGui:WaitForChild("InfoUI") function hover() if mouse.Target.Parent.Name == "Item1" then infogui.INFO1.Visible = true infogui.INFO1.Position = UDim2.new(0, mouse.X, 0, mouse.Y) else infogui.INFO1.Visible = false end end 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
.
local UserInputService = game:GetService("UserInputService") local mouse = game.Players.LocalPlayer:GetMouse() local infogui = game.Players.LocalPlayer.PlayerGui:WaitForChild("InfoUI") function hover() if mouse.Target then -- Check if there is actually a Target if mouse.Target.Parent.Name == "Item1" then infogui.INFO1.Visible = true infogui.INFO1.Position = UDim2.new(0, mouse.X, 0, mouse.Y) else infogui.INFO1.Visible = false end else infogui.INFO1.Visible = false -- If there isn't a target, make the infoUI invisible end end 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!