I’m trying to make it so the player can switch what tool they want for each keybind. (1,2,3,4,5 etc.)
So to do this I have to check what gui the mouse is over, I’ve looked at many posts about this, and tried solution, but all don’t see to work.
If you could explain how to really use
local StarterGui = game:GetService("StarterGui")
local Mouse =game.Players.LocalPlayer:GetMouse()
local Guis = StarterGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y) -- This is the line I don't know how to use.
Any examples or code about StarterGui:GetGuiObjectsAtPosition(), would be greatly appreciated.
local PlayerGui = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
while wait() do
local Mouse =game.Players.LocalPlayer:GetMouse()
local Guis = PlayerGui:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y)
for i,v in pairs(Guis) do
print(v, i)
end
end
You can also use the MouseEnter event and store the gui in an ObjectValue.
local Gui = nil --Replace this with the gui object
local Object = nil --Replace this with the object value where the gui will be stored in
Gui.MouseEnter:Connect(function(x, y)
wait()
Object.Value = Gui
end)
Gui.MouseLeave:Connect(function(x, y)
Object.Value = nil
end)