Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to use mouse.Target on a gui?

I'm making a gui where you hover over a frame and it shows the description of the gui you are hovering over aka health and speed etc. but it's only showing one value from part2 to every other item that you can hover over part2 and part3 and part1 is a folder locatated in replicatestorage and all the values in located there but when you hover over part2 then it's shows that information to all of the other.

Heres the script:

local mouse = player:GetMouse()
for _,a in pairs(game.ReplicatedStorage.Enemies:GetChildren()) do
	local sample = gui.Tabs.Tab.UIGridLayout.Sample:Clone()
	sample.Parent = gui.Tabs.Tab
	sample.Name = a.Name
	sample.Price.Text = a.Price.Value
	sample.Image = "rbxassetid://"..a.Image.Value
	gui.Tabs.Description.ItemName.Text = "DESCRIPTION"
	gui.Tabs.Description.Health.Text = "HEALTH: "..a.Health.Value
	
	sample.MouseEnter:connect(function()
		gui.Tabs.Description.Visible = true
	end)
	sample.MouseLeave:connect(function()
		gui.Tabs.Description.Visible = false
	end)
	
	function hover()
		--gui.Tabs.Description.Visible = true
		gui.Tabs.Description:TweenPosition(UDim2.new(0, mouse.X, 0, 170), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.1, true);
	end
	mouse.Move:connect(hover)

--	sample.MouseButton1Click:connect(function()
--		if sample:IsA("ImageButton") then
--			print(a.Desc.Value)
--		end
--	end)
end

1 comment

0

i was thinking using a 3d part that always faces the camera so it will look like its a gui

1 answer

✓ Accepted answer

Mouse.Target is not possible on GUI objects as it only returns parts.

Your best possible option is to use the MouseEnter and MouseLeave events on each GUI object to know when the mouse enters and leaves the GUI.

3 comments

0

But if i use mouseEnter then i can't change the description to have the same health text as the value in the replicatedStorage without hard coding

0

Its not ideal, but its what you gotta do to know if the mouse if over a gui element. The only other way I can think of is 2D mathematics, but that is way too complicated for what you want to do.

0

m okay

This discussion is preserved as it was. New answers, comments, and votes are closed.