V_lidus
(xda)
January 13, 2022, 3:44am
#1
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
VeriBaesix
(veribaesix)
January 13, 2022, 3:53am
#2
Can you show us your current script?
V_lidus
(xda)
January 13, 2022, 3:55am
#3
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)
V_lidus
(xda)
January 13, 2022, 3:55am
#4
Don’t mind the extra services, there’s more I plan to do.
VeriBaesix
(veribaesix)
January 13, 2022, 4:04am
#5
(I’m not sure if this works)
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)
V_lidus
(xda)
January 13, 2022, 4:06am
#6
What am I supposed to do with the frame?
VeriBaesix
(veribaesix)
January 13, 2022, 4:07am
#7
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}
.
V_lidus
(xda)
January 13, 2022, 4:08am
#8
No I get that, but how does this help me set borders so it doesn’t go past this point?
VeriBaesix
(veribaesix)
January 13, 2022, 4:12am
#9
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
V_lidus
(xda)
January 13, 2022, 4:15am
#10
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.
VeriBaesix
(veribaesix)
January 13, 2022, 4:23am
#11
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
V_lidus
(xda)
January 13, 2022, 4:25am
#13
This ended up being the case, thanks. But it still didn’t solve my border problem
VeriBaesix
(veribaesix)
January 13, 2022, 4:42am
#15
Why do you have 2 frames (xscaleborder and yscaleborder)? Try using 1 frame with these properties
V_lidus
(xda)
January 13, 2022, 4:43am
#16
Because they’re two different setups, one image is different than the other, and the IDs are different as well.
VeriBaesix
(veribaesix)
January 13, 2022, 4:44am
#17
Ahh, parent the frame to a ScreenGui instead of the YScale and the XScale.
1 Like
V_lidus
(xda)
January 13, 2022, 4:47am
#18
You’re a god, that was it. Any way to fix that overlap on the bottom right though?
1 Like
VeriBaesix
(veribaesix)
January 13, 2022, 5:23am
#19
hmmm, idk if this will fully fix it but try to change the AnchorPoint
of the Marker to 0, 0.5
.