When mouse touches area near object, block and text appears

I’ve been trying to script on how to make a block and text appear when a mouse is near an object. But it doesn’t appear when you click on the object.



Can you please show examples of what you tried/is trying to achieve what you’re looking for?

you can simply use the players mouse to do this. Here is a script example:

local mouse = game.Players.LocalPlayer:GetMouse()
local targetedobject
while true do
if mouse.Target.Name == "Cookie" or mouse.Target.Parent.Name == "Cookie" then
if mouse.Target.Description.Enabled == false and mouse.Target.SelectionBox.Visible == true then
mouse.Target.Description.Enabled = true --For the text gui above it
mouse.Target.SelectionBox.Visible = true ---For the white box around the object
targetedobject = mouse.Target
if targetedobject then
if targetedobject.SelectionBox.Visible == true and targetedobject.Description.Enabled == true then
targetedobject.SelectionBox.Visible = false
targetedobject.Description.Enabled = false

Wouldn’t that cause a lot of perfomance issues because you didn’t place a yield?(I forgot if yield should be the correct word for the case, but take it as a wait().)

yes, I forgot to add more checks such as if they aren’t visible/enabled. The yield can easily be added but if I add the visible/enabled checks it shouldn’t lag the server.
Edit: plus, I did say example
Edit2: I will edit the script and add some sanity checks with the yield.

1 Like

You can create an artificial hitbox by using the function-- model:GetExtentsSize.
This will return a Vector3 of a model you call on the function, which you can then weld to the primarypart of the model and use Mouse.Target to handle what you want done.

Please set the size to the returned Vector3 from GetExtentsSize.

Mouse.Target – Mouse | Documentation - Roblox Creator Hub
Model:GetExtentsSize – Model | Documentation - Roblox Creator Hub