How would I go about making a player enable one item when they try to enable another item?

So basically I am making a shop system that consists of items, when a player enables one item I want them to obtain it but when it enables another item then it obtains 2 items at once, how would I go about making the player enable one item and if they want to enable another item then the item they had will disappear and they will obtain that one item.

Just like in Epic Minigames where when you obtain one item you will only get that one item and not anything else.

The best solution here would be to have a BoolValue somewhere in PlayerGui and Check if it’s true,if true then do the code for it else just add 1st effect

EDIT:

if (AlreadyEquipped  == true) then
--Code
else
--OtherCode
end

Pretty easy.

  1. Set a Bool Variable for each item and set the first one to true and the other ones to false
  2. When the player obtains another tool, set the new item’s bool variable to true and the old one to false
  3. Check the variable which is set to true and give/remove the right item.

Incase you don’t know how to set bool variables:

local item1 = true
local item2 = false
local item3 = false

Then check them like this:

if item1 = false and item2 = true then
     -- remove item1 and give item2
end

Please tell me if that helped,
Theyoloman1920

1 Like

Well You don’t check like that probably a typo mistake right there i am just gonna correct it here:

NOTE: There are == in if Statements Instead of =

1 Like

Oh right so you mean like create a boolean variable for every item and if the player enables one item then set the boolean of that item to true and the rest of the booleans to false, right?

Oh and I know how to set bool variables, thank you.

Yes just like that

[30 characaters]

Oh, yeah, I missed that. Thanks for the correction once again! I appreciate it!

Alright, but is it safe if I would use a while loop to check if a boolean value is true because it will only check once and not check again…

Exactly!
PS, I saw that you were a programmer after I posted this post, and I was to lazy to edit it.

You can make a Actual BoolValue and use

BoolValue:GetPropertyChangedSignal:Connect(function()
--Code here
end)
1 Like

Alright so something like this would be good enough:


local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local RedSword = PlayerGui:WaitForChild("Folder"):WaitForChild("RedSwordBool")

RedSwordEnableButton.MouseButton1Click:Connect(function()
if RedSword == false then
   RedSword = true

    ---- the rest of the boolean values will be set to false

end)


Yes, that looks good. And if the RedSword = true then give the item.

1 Like

Alright, thank you, I’m going to try that out and see if it works, I’ll get back to you. (It should work)

Great! (30 characters)

Well Actually yes But No there are a few error you must fix

A fix would be:

if RedSword.Value == false then
RedSword.Value = true
        end --you also forgot this if statment "end"
end)

Yeah, don’t worry about that, I just gave an example of what it could be, I left it out by purpose.

Make sure to fix .Value though

Yeah I know, as I said I left it out by purpose. I know that boolean values have a value.

Ok Happy developing!

[30 characters]

Alright, so after me sorting out the code because I messed it up, it came to the conclusion that it works but one more thing, how do we save it using a datastore, maybe I could create a table that is contained with those boolean values and save it like that?