I have an inventory GUI that has 2 modes, those two modes are as follows:
craft: The materials that can be used when crafting. build: The buildables that you can place on your plot
Now the script that I have that controls the button to toggle between craft and build mode contains the following:
script.Parent.MouseButton1Click:connect(function() local value = game.Players.LocalPlayer.PlayerGui.Inventory.mode.Value if value == "craft" then value = 'build' script.Parent.Text = "build" elseif value == "build" then value = 'craft' script.Parent.Text = "craft" end end)
With the default state of the inventory being build mode, when I hit the button, it changes to craft mode, however when it is clicked again it does not switch back to build mode. I assumed the problem was when it ran through the script, it saw the value as craft then switched it to build, then the next elseif statement saw it as build and switched it back to craft, resulting in no change. I decided that if this was the problem than a possible solution would be to break out of the if statement before it could continue to the elseif statement. I have a couple questions:
If breaking from the if statement would be a valid solution to this problem, how could I break out of it and If breaking from the if statement wouldn't be a proper solution, what would be?
Your problem is how you're attempting to set the value. The value variable is a just a variable containing the mode's value prior to the if statement, so lines 4 and 7 will only change that variable to a string. This doesn't accomplish anything.
If you want to change the value object, you have to make the 'value' variable reference the actual value object. Then you can index the 'Value' property to set it.
script.Parent.MouseButton1Click:connect(function() local value = game.Players.LocalPlayer.PlayerGui.Inventory.mode if value == "craft" then value.Value = 'build' script.Parent.Text = "build" elseif value == "build" then value.Value = 'craft' script.Parent.Text = "craft" end end)