Is there a way i can make it so the mouse entered and leave functions will respect the z index of other gui elements? Because if I have one that is overlapping another slightly, and I scroll over the center point between the two, it will fire both of the mouse entered functions.
This is an example, I’m trying to use these cards, and i need only one to be selected at a time (they rise up a little out jogging like a normal deck of cards), though i can’t seem to figure a way of doing that. I fired a seperate event for when a “selected” value changes (a value saying which card is selected), and then firing the tween of the original positions of all the other cards, But that doesn’t seem to be doing anything, the card still stays selected when the mouse is in between the two cards.
You can have a table with cards that are being hovered, then if that table ever has more more then 1 you can only “Select” the one with the higher ZIndex.
I’m not aware of a way to have MouseEnter and MouseLeave fire with respect to ZIndex.
local Hovered = {}
local Cards = {card1, card2, card3, card4}
local Selected
local UpdateSelected = function()
if #Hovered == 1 then
Selected = Hovered[1]
elseif #Hovered == 0 then
Selected = nil
elseif #Hovered > 1 then
table.sort(Hovered, function(a, b)
return a.ZIndex > b.ZIndex
end)
Selected = Hovered[1]
end
end
for i = 1, #Cards do
Card[i].MouseEnter:Connect(function()
if table.find(Hovered, Card[i]) == nil then
table.insert(Hovered, Card[i])
UpdateSelected()
end
end)
Card[i].MouseLeave:Connect(function()
if table.find(Hovered, Card[i]) ~= nil then
table.remove(Hovered, table.find(Hovered, Card[i])
UpdateSelected()
end
end)
end
I havn’t tested this code, I just wrote it here so it may error.