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

Item Title/Descriptions; How to interrupt if GUI is already there?

Asked by 3 years ago
for _, v in pairs(ItemRooms) do
    local Peadastol = v.Pedastol
    Peadastol.Touched:Connect(function(p)
        if p.Parent:FindFirstChild("Humanoid") and DescCoolDown == false then
            DescCoolDown = true
            for _, x in pairs(v:GetDescendants()) do
                if x:IsA("Model") and game.ReplicatedStorage.Items:FindFirstChild(x.Name) then
                    local GUI = script.DescGUI:Clone()
                    local Desc = x:FindFirstChild("Description")
                    local Player = game.Players:FindFirstChild(p.Parent.Name)
                    GUI.Holder.Description.Text = Desc.Value
                    GUI.Holder.Item.Text = x.Name
                    GUI.Parent = Player.PlayerGui
                    wait(5)
                    GUI:Destroy()
                    DescCoolDown = false
                end
            end
        end
    end)
end

So, I have this script that checks if you touch a pedestal, it takes the item name and description (within the item) and places a gui into you.

I am wondering how I would go about deleting the gui when you grab another item and the 1st gui isnt done showing you the item and description yet?

For example, you grab an item and it shows you the Item and description. Then, before the wait(5) is over you grab another item. I want it to Delete the old gui and make a new one so they dont overlap...

1 answer

Log in to vote
0
Answered by 3 years ago

I had a few people help me out

Server Script

for _, v in pairs(ItemRooms) do
    local Pedestal = v.Pedestal

    Pedestal.Touched:Connect(function(p)
        if p.Parent:FindFirstChild("Humanoid") and DescCoolDown == false then
            DescCoolDown = true

            for _, x in pairs(v:GetDescendants()) do
                if x:IsA("Model") and game.ReplicatedStorage.Items:FindFirstChild(x.Name) then
                    local Player = game.Players:GetPlayerFromCharacter(p.Parent)
                    local Desc = x:FindFirstChild("Description")
                    local Rarity = x:FindFirstChild("Rarity")
                    local Item = x.Name
                    ItemGuiEvent:FireClient(Player, Item, Desc.Value, Rarity.Value)
                end
            end

            DescCoolDown = false
        end
    end)
end

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.RemoteEvents.ItemGuiEvent
local CurrentItem = nil

local function InvokeGUI(Item, Desc, Rarity)
    if CurrentItem == Item then return end
    CurrentItem = Item
    script.Parent.Holder.RareIndex.Text = Rarity
    script.Parent.Holder.Item.Text = Item
    script.Parent.Holder.Description.Text = Desc
    script.Parent.Holder.Visible = true
    wait(3)
    if CurrentItem == Item then
        script.Parent.Holder.Visible = false
        CurrentItem = nil
    end
end

Event.OnClientEvent:Connect(InvokeGUI)
Ad

Answer this question