today I was testing out my game when I realised that when I hovered the shop ui and then I hovered the trade gui, the shop gui would still act like its hovered. But hovering the trade gui and then the shop ui works as expected, here is a clip of the issue:
You can see in the video that when I hover the trade UI and then the shop GUI it works fine but when I hover the Shop UI first and then I hover the trade UI the bug happens.
local Player = game.Players.LocalPlayer
Player:WaitForChild("PlayerGui")
local Mouse = Player:GetMouse()
local Functionality = game.ReplicatedStorage:WaitForChild("Functionality")
local UICloneableFolder = game.ReplicatedStorage:WaitForChild("Cloneable"):WaitForChild("UI")
local UIHoverStroke = UICloneableFolder:WaitForChild("HoverStroke")
local Sounds = Functionality:WaitForChild("Sounds")
local SFX = Sounds:WaitForChild("SFX")
local TweenService = game:GetService("TweenService")
local HoverTI = TweenInfo.new(.35, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false)
local HoverInfoUI = Player.PlayerGui:WaitForChild("Other"):WaitForChild("HoverInfoUI")
local HoverInfoUITextLabel = HoverInfoUI:WaitForChild("Text")
local HoverInfoUIOrgSize = HoverInfoUI.Size
local Camera = workspace.CurrentCamera
local function HoverEffects(Button: GuiButton)
if Button:GetAttribute("DontAutoScale") == true then
return
end
-- // Variables
local HoverIntensity = 0.2
local ButtonIsSideButton = Button:GetAttribute("IsSideButton")
local ShowHoverInfoUIOnHover: string?
local MouseConnection
-- // Setting Connections
if Button.AnchorPoint ~= Vector2.new(0.5, 0.5) then
warn(Button, "AnchorPoint is not 0.5, 0.5, please change")
end
local OrgButtonSize = Button.Size
if Button:GetAttribute("OrgSize") then
OrgButtonSize = Button:GetAttribute("OrgSize")
end
if Button:GetAttribute("HoverIntensity") then
HoverIntensity = Button:GetAttribute("HoverIntensity")
end
local ShowHoverInfoUIOnHover = Button:GetAttribute("ShowHoverInfoUI")
local ExpandSize = UDim2.new(OrgButtonSize.X.Scale * (1 + HoverIntensity * 0.25), 0, OrgButtonSize.Y.Scale * (1 + HoverIntensity))
local ClickSize = UDim2.new(OrgButtonSize.X.Scale / (1 + HoverIntensity), 0, OrgButtonSize.Y.Scale / (1 + HoverIntensity))
Button.MouseEnter:Connect(function()
--UIHoverStroke.Parent = Button
SFX.Hover:Play()
TweenService:Create(Button, HoverTI, {Size = ExpandSize}):Play()
if ButtonIsSideButton then
TweenService:Create(Button, HoverTI, {Rotation = -7}):Play()
end
if ShowHoverInfoUIOnHover then
HoverInfoUITextLabel.Text = ShowHoverInfoUIOnHover
--HoverInfoUI.Size = UDim2.fromScale(HoverInfoUITextLabel.TextBounds.X / workspace.CurrentCamera.ViewportSize.X, HoverInfoUI.Size.Y.Scale)
HoverInfoUI.Visible = true
if MouseConnection then
MouseConnection:Disconnect()
end
if Button.Position.X.Scale > 0.9 then
HoverInfoUI.AnchorPoint = Vector2.new(1, 0)
else
HoverInfoUI.AnchorPoint = Vector2.new(0, 0)
end
MouseConnection = Mouse.Move:Connect(function()
HoverInfoUI.Position = UDim2.fromScale(Mouse.X / workspace.CurrentCamera.ViewportSize.X, Mouse.Y / workspace.CurrentCamera.ViewportSize.Y + 75 / workspace.CurrentCamera.ViewportSize.Y)
end)
end
end)
Button.MouseLeave:Connect(function()
UIHoverStroke.Parent = UICloneableFolder
TweenService:Create(Button, HoverTI, {Size = OrgButtonSize}):Play()
if ButtonIsSideButton then
TweenService:Create(Button, HoverTI, {Rotation = 0}):Play()
end
if ShowHoverInfoUIOnHover then
if MouseConnection then
MouseConnection:Disconnect()
end
HoverInfoUI.Visible = false
end
end)
Button.Activated:Connect(function()
SFX.Click:Play()
--UIHoverStroke.Parent = UICloneableFolder
Button.Size = ClickSize
TweenService:Create(Button, HoverTI, {Size = ExpandSize}):Play()
end)
end
--// Connecting
for _, v in Player:WaitForChild("PlayerGui"):GetDescendants() do
local s, e = pcall(function()
v:SetAttribute("OrgPos", v.Position)
end)
if not v:IsA("GuiButton") then
continue
end
HoverEffects(v)
end
Player.PlayerGui.DescendantAdded:Connect(function(v)
local s, e = pcall(function()
v:SetAttribute("OrgPos", v.Position)
end)
if not v:IsA("GuiButton") then
return
end
HoverEffects(v)
end)
The code looks all good. I think the problem is that when the mouse enters the shop gui, the size expands and the gui rotates. So the “hit box” of the shop gui overlaps the trade gui’s hit box therefore still registering the mouse on the gui. Maybe try spacing the gui out more and see if that works.