How to make a equip/unequip text

Hi,

How would I make a button so when you click it the text changes to equip. Then when you click it again the text changes to unequip. Then it changes to equip and so on. The original text of the button will just be unequip.

I’m not sure how exactly to do it since every time I attempted to do so it wouldn’t work.

So I would prefer it to be in some sort of form that’s used if statements with strings. So like…

Local Button = script.Parent
If Button.Text == “unequip” then
Button.Text = “equip”
end)

If Button.Text == “equip” then
Button.Text = “unequip”
end)

The script above just breaks but I would like something along those lines.

Thanks


local equipped = false

local button = script.Parent

local function onButtonPressed()

   if equipped then

    equipped = false

    button.Text = 'equip'

    return

   elseif not equipped then

    equipped = true

    button.Text = 'unequip'

   end

end

use MouseButton1Down to handle when button is clicked.

button.MouseButton1Down:Connect(onButtonPressed)

Just 5 lines.

local btn = script.Parent

btn.MouseButton1Click:Connect(function()
    btn.Text = (if btn.Text == 'equip' then 'unequip' else 'equip')
end)

How does this script work?
Blank space

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.