Need help with a GUI indicator

I’m trying to make a main menu system, and part of it depicts an indicator on where your mouse is on the Y and X Axis. It’ll display its number value, but I also want it to move the arrow indicator up and down as well. The problem here, is that I don’t want it going over the GUI object, and I don’t know how I would make a ‘border restriction’ I guess? If someone can help, that’d be fantastic.

THE QUESTION: How would I move the arrow indicator based on the Y & X Axis of the mouse, and not have it leave the confinement of the boarder?

1 Like

Can you show us your current script?

Yeah no problem. Here it is:

local players = game:GetService("Players")
local lplayer = game:GetService("Players").LocalPlayer
local ts = game:GetService("TweenService")
local gs = game:GetService("TweenService")
local lighting = game:GetService("Lighting")
local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")

local mouse = lplayer:GetMouse()
local base = script.Parent
local configvalues = script.Parent:WaitForChild("Values")

local inmenu = true
local indicatorlocked = true
local intopbar = false

uis.MouseIconEnabled = false

if configvalues.DevWatermark.Value == true then
	
	base.Watermark.Visible = true
	
end

function indicatormovement()
	
	if inmenu == true and indicatorlocked == true and intopbar == false then

		base.Indicator.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
		
		base.YScale.Number.Text = mouse.Y
		base.XScale.Number.Text = mouse.X
		
		base.YScale.Marker.Position = UDim2.new(0, 0, 0, mouse.Y)
		base.XScale.Marker.Position = UDim2.new(0, 0, 0, mouse.X)

	end
	
end

rs.Heartbeat:Connect(function()
	
	indicatormovement()
	
end)

base.TopBar.MouseEnter:Connect(function()
	
	indicatorlocked = false
	intopbar = true
	
	uis.MouseIconEnabled = true
	
end)

base.TopBar.MouseLeave:Connect(function()

	indicatorlocked = true
	intopbar = false

	uis.MouseIconEnabled = false

end)

Don’t mind the extra services, there’s more I plan to do.

(I’m not sure if this works)

  1. Create an invisible GUI Frame with a size of {1, 0},{1, 0}
local invisibleFrame = -- REFERENCE THE INVISIBLE FRAME HERE
local players = game:GetService("Players")
local lplayer = game:GetService("Players").LocalPlayer
local ts = game:GetService("TweenService")
local gs = game:GetService("TweenService")
local lighting = game:GetService("Lighting")
local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")

local mouse = lplayer:GetMouse()
local base = script.Parent
local configvalues = script.Parent:WaitForChild("Values")

local inmenu = true
local indicatorlocked = true
local intopbar = false

uis.MouseIconEnabled = false

if configvalues.DevWatermark.Value == true then
	
	base.Watermark.Visible = true
	
end

function indicatormovement()
	
	if inmenu == true and indicatorlocked == true and intopbar == false then

		base.Indicator.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
		
		base.YScale.Number.Text = mouse.Y
		base.XScale.Number.Text = mouse.X
		
		base.YScale.Marker.Position = UDim2.new(0, 0, mouse.Y / invisibleFrame.AbsoluteSize.Y, 0)
		base.XScale.Marker.Position = UDim2.new(0, 0, mouse.X / invisibleFrame.AbsoluteSize.X, 0)

	end
	
end

rs.Heartbeat:Connect(function()
	
	indicatormovement()
	
end)

base.TopBar.MouseEnter:Connect(function()
	
	indicatorlocked = false
	intopbar = true
	
	uis.MouseIconEnabled = true
	
end)

base.TopBar.MouseLeave:Connect(function()

	indicatorlocked = true
	intopbar = false

	uis.MouseIconEnabled = false

end)

What am I supposed to do with the frame?

The frame is to get the AbsoluteSize of the player’s screen. Just make it have a BackgroundTransparency of 1 and a size of {0, 1}, {0, 1}.

No I get that, but how does this help me set borders so it doesn’t go past this point?

Lets say the AbsoluteSize of the Frame is 1366, 768. Then the mouse’s current position is at 1366, 768 (bottom right corner of the screen).

With these lines:

base.YScale.Marker.Position = UDim2.new(0, 0, mouse.Y / invisibleFrame.AbsoluteSize.Y, 0)
base.XScale.Marker.Position = UDim2.new(0, 0, mouse.X / invisibleFrame.AbsoluteSize.X, 0)

You will convert:
the X Marker’s Position to UDim2.new(0, 0, 1, 0) (which is the most bottom area of the Marker)
the Y Marker’s Position to UDim2.new(0, 0, 1, 0) (which is the most bottom area of the Marker)

1 Like

Okay, so this is what I have here:

base.YScale.Marker.Position = UDim2.new(0, 0, 0, mouse.Y / yscaleborder.AbsoluteSize.Y)
base.XScale.Marker.Position = UDim2.new(0, 0, 0, mouse.X / xscaleborder.AbsoluteSize.X)

But now the marker barely moves at all.

Can you show us the Markers in the Explorer?

This is because you’re setting the Y Offset instead of the Scale (3rd parameter, not 4th)

1 Like

This ended up being the case, thanks. But it still didn’t solve my border problem

Here you go:

Why do you have 2 frames (xscaleborder and yscaleborder)? Try using 1 frame with these properties

Because they’re two different setups, one image is different than the other, and the IDs are different as well.
image

Ahh, parent the frame to a ScreenGui instead of the YScale and the XScale.

1 Like

You’re a god, that was it. Any way to fix that overlap on the bottom right though?

1 Like

hmmm, idk if this will fully fix it but try to change the AnchorPoint of the Marker to 0, 0.5.