I'm trying to create a shop tooltip to display information of an item in a shop.
It takes information by name of the item. The main code is in a Local Script in a ScreenGui. The information is saved on ReplicatedStorage (module script).
I had 1 item and it worked fine. After I try adding another item it started glitching and malfunctioning. It started to have duplicates or only display one specific text. Also, I have to start with the fireball in order for it to work a bit.
Evidence: https://gyazo.com/5f3d473abf8869660b02d7c31d95d914.gif https://gyazo.com/71d08655a24b0b3b021b1659159bd095.gif
This is the Script that detect Mouse Enter and Mouse Move:
--// TOOL TIP SHOP \\ -- local ShopShowToolTipSizeX = ShopToolTip.Size.X.Offset spawn(function() for _, item in pairs(Shop:GetChildren()) do if item:IsA('ImageButton') then item.MouseEnter:Wait() ShopToolTip.Visible = true ShopToolTip.ItemName.Text = 'Name: '..item.Name ShopToolTip:WaitForChild('ItemDesc').Text = 'Desc: '..MovesInfo[item.Name].Desc ShopToolTip.ItemDamage.Text = 'Dmg: '..MovesInfo[item.Name].Damage ShopToolTip.ItemPrice.Text = 'B$ '..MovesInfo[item.Name].Cost item.MouseMoved:Connect(function(X, Y) ShopToolTip.Position = UDim2.new(0, (X - ShopShowToolTipSizeX) - 10, 0, Y) ShopToolTip.Visible = true item.MouseLeave:Wait() ShopToolTip.Visible = false Shop.MouseLeave:Wait() ShopToolTip.Visible = false end) end end end)
Any support and feedback that improves this code or fixes the problem are appreciated. Thank you for reading.
That's because you're using MouseEnter:Wait()
instead of connecting to the event, so it only gets the informations once for each item, and besides that, has to be in the order of the loop.
You should connect to the event instead, like you did with MouseMoved
--// TOOL TIP SHOP \\ -- local ShopShowToolTipSizeX = ShopToolTip.Size.X.Offset spawn(function() for _, item in pairs(Shop:GetChildren()) do if item:IsA('ImageButton') then item.MouseEnter:Connect(function() ShopToolTip.Visible = true ShopToolTip.ItemName.Text = 'Name: '..item.Name ShopToolTip:WaitForChild('ItemDesc').Text = 'Desc: '..MovesInfo[item.Name].Desc ShopToolTip.ItemDamage.Text = 'Dmg: '..MovesInfo[item.Name].Damage ShopToolTip.ItemPrice.Text = 'B$ '..MovesInfo[item.Name].Cost item.MouseLeave:Wait() ShopToolTip.Visible = false end) item.MouseMoved:Connect(function(X, Y) ShopToolTip.Position = UDim2.new(0, (X - ShopShowToolTipSizeX) - 10, 0, Y) end) end end end)