I have a GUI shop that has buttons. The button's are there to buy weapons, when you own it and then click it again, it displays a text label "Equipped". I made a script so that it can show only one weapon already equipped, meaning once one button is clicked the text label of the button you clicked says "equipped", the other text labels that say equipped are invisible. The problem is that the equipped text labels aren't disappearing after clicking the buttons. What did I do wrong?
This is the equipped text label's script:
local player = game.Players.LocalPlayer
local sword = player:WaitForChild("PersonalSword")
if sword.Value == "Darkheart" then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
This is the button's script:
local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local points = player:WaitForChild("leaderstats")["Player Points"]
local value = 2500 -- edit here
local name = "DarkHeartSword" -- here
local altname = "Darkheart"
local swords = script.Parent.Parent:GetChildren()
function TweenReceipt()
local debounce = false
if debounce == false then
debounce = true
script.Parent.Parent.Parent.MoneyNeeded.Visible = true
script.Parent.Parent.Parent.MoneyNeeded.Amount.Text = value - points.Value
script.Parent.Parent.Parent.MoneyNeeded:TweenPosition(UDim2.new(0, 300, 0, -100),"Out", "Quart", 1.5)
wait(2.5)
script.Parent.Parent.Parent.MoneyNeeded:TweenPosition(UDim2.new(0, 1300, 0, -100), "Out", "Quart", 0.2)
script.Parent.Parent.Parent.MoneyNeeded.Position = UDim2.new(0, -1000, 0, -100)
script.Parent.Parent.Parent.MoneyNeeded.Visible = false
end
debounce = false
end
script.Parent.MouseButton1Click:connect(function()
if not player.Swords:FindFirstChild(altname) then -- edit here
if points.Value >= value then -- buying clause
points.Value = points.Value - value
local Sword = Instance.new("BoolValue", player.Swords)
Sword.Name = altname -- here
script.Parent.Owned.Visible = true
else
TweenReceipt()
end
elseif script.Parent.Equipped.Visible == false then
for i, v in pairs(swords) do
if v.Name ~= name then
v.Equipped.Visible = false
script.Parent.Equipped.Visible = true
player.Swords.Darkheart.Value = true -- edit here
player.PersonalSword.Value = altname
end
end
elseif script.Parent.Equipped.Visible == true then
player.Swords.Darkheart.Value = false -- edit here too
end
end)
if player:WaitForChild("Swords"):FindFirstChild(altname) then -- final edit
script.Parent.Owned.Visible = true
end

2 comments
Put a CurrentlyEquipped variable.
The currentlyequipped variable is the sword value