I have a shop system with swords that the player can purchase, but I’m not quite sure how to implement a system to know which sword the player has equipped. I have some bool values that are set to true if the player has purchased a sword as well as a stringvalue which is set to whatever sword the player equips, but I want to be able to display the text in this gui
Let me rephrase this. I can use the bool values and a combination of checking the current sword to tell what is equipped, but I don’t know if I should update the text that says ‘Purchase’ every second or on heartbeat or whatever since I don’t want to have memory leaks and lag from constant checks.
local PurchaseButtons = {PATH_TO_BUTTONS} --Change to a table of the buttons
for _,b in PurchaseButtons do
b.MouseButton1Click:Connect(function()
if b.Text == 'Equip' then
for _,b2 in PurchaseButtons do
if b2.Purchased.Value == true then --Change to the Purchased BoolValue relative to b2
b2.Text = 'Equip'
else
b2.Text = 'Purchase'
end
end
b.Text = 'Equipped'
PATH_TO_PLAYERS_CURRENT_SWORD_VALUE.Value = b.Parent.Name --Change to the name of the sword relative to 'b'
end
end)
end
What this script does is replace all button’s text to Equip if its purchased already or to Purchase if it isn’t, and then immediately set the text of the button that was clicked to be equipped to Equipped
The script doesnt do anything if the clicked button’s text is Purchase* or Equipped
*Meaning this does not replace or make up for the purchase script.