-
What do you want to achieve? ; Im trying to make a system where when a player hover the mouse over a certain cube, it enables a specific UI with the cube informations.
-
What is the issue? ; When the mouse hover the Cube too rapidly, it sometimes break and leave the UI enabled.
-
What solutions have you tried so far? : I tried to look onto the Developer hub but i didn’t find anything about this, there’s probably a solution to this but i can’t seem to find it.
Example : mousehover bug - Clipped with Medal.tv
My script :
local CollectionService = game:GetService("CollectionService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local LP = Players.LocalPlayer
local debounce = {}
local function MouseClickedBlock(blocks)
local blockName = tostring(blocks.Name)
if debounce[blockName] then
return
end
debounce[blockName] = true
local BlocksInfos = RS.Remotes.Main.C_C:InvokeServer(blockName)
task.wait(0.1)
debounce[blockName] = false
end
local function MouseHoverEnterBlock(blocks)
local blockName = tostring(blocks.Name)
if debounce[blockName] then
return
end
debounce[blockName] = true
local BlocksInfos = RS.Remotes.Main.C_I:InvokeServer(blockName)
blocks.Highlight.Enabled = true
local MouseInfos = LP.PlayerGui.GameUI.MouseInfos
MouseInfos.Visible = true
MouseInfos.BlockName.Text = blockName
MouseInfos.BlockRarity.Text = "1 / " .. BlocksInfos[1].Rarity
MouseInfos.BlockValue.Text = BlocksInfos[1].Value .. "$"
MouseInfos.BlockName.BlockNameBG.Text = blockName
MouseInfos.BlockRarity.BlockRarityBG.Text = "1 / " .. BlocksInfos[1].Rarity
MouseInfos.BlockValue.BlockValueBG.Text = BlocksInfos[1].Value .. "$"
end
local function MouseHoverLeaveBlock(blocks)
local blockName = tostring(blocks.Name)
if not debounce[blockName] then
return
end
debounce[blockName] = false
blocks.Highlight.Enabled = false
local MouseInfos = LP.PlayerGui.GameUI.MouseInfos
MouseInfos.Visible = false
end
local function setupClickDetector(blocks)
local BCD = blocks:FindFirstChildOfClass("ClickDetector")
if BCD then
BCD.MouseHoverEnter:Connect(function()
MouseHoverEnterBlock(blocks)
end)
BCD.MouseHoverLeave:Connect(function()
MouseHoverLeaveBlock(blocks)
end)
BCD.MouseClick:Connect(function()
MouseClickedBlock(blocks)
end)
end
end
for _, blocks in pairs(CollectionService:GetTagged("BlockClick")) do
setupClickDetector(blocks)
end
CollectionService:GetInstanceAddedSignal("BlockClick"):Connect(function(blocks)
setupClickDetector(blocks)
end)