Summary
Basically, I have an inventory system in my game. You touch the item on the ground, it copies the id of that item into the slot in your inventory. When you click on the inventory slot, the other slots fade out and an "equip" button appears. You equip the item, the gui returns to normal and it sets the "WeaponEquipped" bool value in the player to true, then the weapon is cloned into your backpack. It also sets the text of the equip button for that slot to "Unequip", so the next time the player clicks the gui, the button says unequip instead of equip. Once you press unequip, the button returns to normal and the item is removed from your backpack.
Problem
Everything works as is, however, I'm having a weird issue where I need to click the gui buttons multiple times before they ever actually do anything. I have no idea how to fix this.
Code
local equip = false
local player = game.Players.LocalPlayer
for _,buttons in pairs(script.Parent:GetChildren())
do
if buttons:IsA("TextButton") then
buttons.MouseButton1Click:connect(function(click)
if equip == false then
buttons.Equip.Visible = true
equip = true
for _,otherbuttons in pairs(script.Parent:GetChildren())
do
if otherbuttons:IsA("TextButton") then
otherbuttons.Visible = false
end
end
buttons.Visible = true
buttons.Equip.MouseButton1Click:connect(function(cl)
buttons.Equip.Visible = false
local id = buttons.Item.Value
if buttons.Equip.Text == "Equip" then
if id > 0 then
if id < 2000 then
if player.Status.WeaponEquipped.Value == false then
for _,tools in pairs(game.ReplicatedStorage:GetChildren())
do
if tools:IsA("Tool") then
if tools.itemid.Value == id then
print("Tool found: "..tools.Name)
local clone = tools:Clone()
clone.Parent = game.Players.LocalPlayer.Backpack
player.Status.WeaponEquipped.Value = true
buttons.Equip.Text = "Unequip"
end
end
end
end
end
end
else
--unequip
buttons.Equip.Text = "Equip"
player.Backpack:ClearAllChildren()
player.Status.WeaponEquipped.Value = false
end
for _,otherbuttons in pairs(script.Parent:GetChildren())
do
if otherbuttons:IsA("TextButton") then
otherbuttons.Visible = true
end
end
equip = false
end)
else
buttons.Equip.Visible = false
equip = false
for _,otherbuttons in pairs(script.Parent:GetChildren())
do
if otherbuttons:IsA("TextButton") then
otherbuttons.Visible = true
end
end
end
end)
end
end

1 comment
first of all you should use button1down instead of click. Click can double fire. Also, a debounce would help! http://wiki.roblox.com/index.php?title=Debounce