I have seen some people releasing their projects so i wanted to try it out let me know if it is useful or if you would use it
what is it exactly? its basically just a script that will show the cost and name of an instance in a billboard gui when you hover over it for example
- Is it useful
- Would you use it?
- Have any suggestions or fixes for performance
TUTORIAL
-
Here is how i made the gui for anyone who wants to know
-
make a folder named HoverOverGuis if you want to change the name you will have to change the variable path for example =
local HoverOverGuis = game.Workspace.DifferentName
- insert a local script into StarterPlayer > StarterPlayerScripts
- copy and paste or choose to read the code
local camera = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local LocalPlayer = game.Players.LocalPlayer
local function mouseRaycast()
local mousePos = uis:GetMouseLocation()
local mouseRay = camera:ViewportPointToRay(mousePos.X, mousePos.Y)
local nonHoverparts = {}
for _, part in pairs(workspace:GetDescendants()) do
if not part:HasTag("HoverGui") then
table.insert(nonHoverparts, part)
end
end
local params = RaycastParams.new()
params.FilterDescendantsInstances = {LocalPlayer.Character}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 25, params) --change 25 to the max distance
return result
end
local HoverOverGuis = game.Workspace.HoverOverGuis
game:GetService("RunService").RenderStepped:Connect(function()
local raycast = mouseRaycast()
if raycast then
local mainGui = raycast.Instance:FindFirstChild("MainGui")
if mainGui then
local frame = mainGui:FindFirstChild("Frame")
if frame then
mainGui.Enabled = true
mainGui.Frame.Details.InstanceName.Text = raycast.Instance.Name
mainGui.Frame.Details.Cost.Text = "Cost: "..raycast.Instance:GetAttribute("Cost")
local TweenServ = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tween = TweenServ:Create(frame, tweenInfo, {Size = UDim2.new(1, 0, 1, 0)})
tween:Play()
end
else
for _, gui in pairs(HoverOverGuis:GetChildren()) do
gui.MainGui.Enabled = false
end
end
else
for _, gui in pairs(HoverOverGuis:GetChildren()) do
local mainGui = gui:FindFirstChild("MainGui")
mainGui.Enabled = false
end
end
end)
Important for non-readers
- the name of your instances will be what shows as the name on the gui
- The cost is an attribute of the instance so for example the donut has a number attribute named “Cost” with the value as 100 i used a number value but i think you can use other things like strings have NOT tested yet
Want To Know How It Works?
-
It gets the current camera, user input service, and local player from the game environment.
-
A function
mouseRaycast
is defined. This function calculates a ray from the camera through the mouse position. It also collects all parts in the workspace that don’t have the “HoverGui” tag. -
It sets up parameters for a raycast operation, excluding the local player’s character from the raycast.
-
The function performs the raycast operation and returns the result.
-
It connects a function to the
RenderStepped
event of the RunService, which runs every frame. This function callsmouseRaycast
. -
If the raycast hits an instance, it checks if the instance has a child named “MainGui”. If it does, it enables the GUI and updates its details.
-
If the raycast doesn’t hit an instance, it disables all “MainGui” instances in the
HoverOverGuis
folder.