Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Tool tip system works for a shop half works the way I want it to work [?]

Asked by 5 years ago

Goal:

I'm trying to create a shop tooltip to display information of an item in a shop.

Setup:

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).

Problem:

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

Script:

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.

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)

Ad

Answer this question