I am wanting to make a very simple and easy storage system (inventory) that I can easy edit latter. I am waning a player to click on the item and a equip ui comes up, player when hits equip and then shows what tool you have equipped.
Ex:
Problem: When I click the item more the twice it does not work
Ex:
Using Disconnect
make it work till I need to equip the item aging
I need help fixing this. I have tried almost every thing. I even remade the script piece by piece.
The script is a local script located in ScreenGui
-- GETTING REQUIRED SERVICES AND OBJECTS
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StorageEvent = ReplicatedStorage:WaitForChild("StorageEvent")
-- REFERENCES TO UI ELEMENTS
local StorageFrame = script.Parent.StorageFrame
local MainFrame = StorageFrame.MainFrame
local InfoFrame = StorageFrame.InfoFrame
-- TRACKING CURRENT SPOT INDEX FOR ITEM PLACEMENT
local currentSpotIndex = 1
-- FUNCTION TO DESTROY UI STROKE FROM ITEM BUTTON
local function destroyUIStroke(spotFrame, itemName)
-- CHECK IF UI STROKE EXISTS AND DESTROY IT
local itemButton = spotFrame:FindFirstChild(itemName)
if itemButton and itemButton:IsA("GuiButton") and itemButton:FindFirstChild("UIStroke") then
itemButton.UIStroke:Destroy()
end
end
-- FUNCTION EXECUTED WHEN EQUIP BUTTON IS CLICKED
local function onEquipButtonClick(itemButton, itemName)
return function()
-- REMOVE UI STROKE FROM OTHER SPOT FRAMES
local spotFrames = StorageFrame.SpotFrames:GetChildren()
for _, spotFrame in ipairs(spotFrames) do
destroyUIStroke(spotFrame, itemName)
end
-- REMOVE EXISTING ITEM BUTTON AND UI STROKE
local existingItemButton = MainFrame:FindFirstChild(itemName)
if existingItemButton then
existingItemButton:Destroy()
return
end
-- CLONE AND SET UI STROKE, THEN MOVE ITEM TO MAIN FRAME
local newUIStroke = script.UIStroke:Clone()
newUIStroke.Parent = itemButton
itemButton:Clone().Parent = MainFrame
-- TOGGLE VISIBILITY OF INFO AND CLOSE BUTTONS
InfoFrame.Visible = false
StorageFrame.CloseTextButton.Visible = true
StorageFrame.CloseTextButtonB.Visible = false
end
end
-- LISTEN TO CLIENT EVENTS FROM SERVER
StorageEvent.OnClientEvent:Connect(function(itemName, value)
if value then
-- GET OR CLONE ITEM BUTTON BASED ON NAME
local itemButton = MainFrame:FindFirstChild(itemName) or script.Template:Clone()
itemButton.Name = itemName
-- PLACE ITEM BUTTON IN THE CURRENT SPOT FRAME
local currentSpot = StorageFrame.SpotFrames["Spot" .. currentSpotIndex]
itemButton.Parent = currentSpot
currentSpotIndex = currentSpotIndex % #StorageFrame.SpotFrames:GetChildren() + 1
-- HANDLE ITEM BUTTON CLICK EVENT
local clickConnection
clickConnection = itemButton.MouseButton1Click:Connect(function()
-- REFERENCES TO INFO ELEMENTS
local nameTextLabel = InfoFrame.NameTextLabel
local equipButton = InfoFrame.EquipButton
-- TOGGLE VISIBILITY OF ELEMENTS AND SET NAME LABEL
StorageFrame.CloseTextButton.Visible = false
StorageFrame.CloseTextButtonB.Visible = true
nameTextLabel.Text = itemButton.Name
InfoFrame.Visible = true
-- CONNECT EQUIP BUTTON CLICK EVENT
equipButton.MouseButton1Click:Connect(onEquipButtonClick(itemButton, itemName))
-- DISCONNECT CLICK EVENT TO PREVENT MULTIPLE CONNECTIONS
clickConnection:Disconnect()
end)
end
end)
How do I make it when the script gets disconnect the but ItemButtons can still can be equipped?