Hi all, I’m trying to make a 3d GUI appear over a part when the mouse is hovered over said part,
I’ve found this
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RunService = game:GetService("RunService")
local MouseGui = script.Parent.AppearMouseUI
RunService.RenderStepped:Connect (function()
if Mouse.Target and Mouse.Target.Name == "HoverPart" then
if Mouse.Target.Name == 'HoverPart' then
MouseGui.Visible = true
local X = Mouse.X
local Y = Mouse.Y
MouseGui.Position = UDim2.new(0,X,0,Y)
else
MouseGui.Visible = false
end
end
end)
However, I don’t have much scripting experience and don’t know where I put it and what I need to do to get it to work. All I’ve done so far is put it into a LocalScript in StarterPlayerScripts, created a brick called ‘HoverPart’, and created a ScreenGui called ‘AppearMouseUI’.
If you could also help me simplify the process of making this script work for multiple parts with different GUI’s for each, that’d be great.
From the looks of that script, it would be in a ScreenGui, in StarterGui, as a LocalScript.
There would be a UI Frame called “AppearMouseUI” that isnt visible by default.
alright so use and just position it when you hover should in theory look something like this
belongs in the ui you want to position (localscript)
local UI = -- Path to ui
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
if Mouse.Target and Mouse.Target.Name == "HoverPart" then
local worldPoint = Mouse.Target.Position
local vector, inViewport = camera:WorldToViewportPoint(worldPoint)
UI.Position = Udim2.new(0,vector.X,0,vector.Y)
end
end)