I made a script that opened and closed a gui every time you clicked a button, it worked. I needed the same script for a different button, so I duplicated the script and put it in a different button and made a few changes to make a different gui appear. For some reason however, the copy of the script wont work, and it gives me an error that says:
CreateTerritoryGui is not a valid member of PlayerGui "Players.Paczki_TCBC.PlayerGui"
(CreateTerritoryGui is the gui I'm trying to make appear, and Paczki_TCBC is my username.)
here is the script that did work:
local Or = 1
local button = script.Parent
local editor = button.Parent.Parent.Editor
editor.Enabled = false
button.MouseButton1Up:Connect(function()
Or = Or * -1
if Or == -1 then
editor.Enabled = true
elseif Or == 1 then
editor.Enabled = false
end
end)
and here is the one that did not work:
local choice = 1
local button = script.Parent
local editor = button.Parent.Parent.CreateTerritoryGui
editor.Enabled = false
button.MouseButton1Up:Connect(function()
choice = choice * -1
if choice == -1 then
editor.Enabled = true
elseif choice == 1 then
editor.Enabled = false
end
end)

3 comments
This could be because the script is trying to find CreateTerritoryGui before it has loaded in try replacing button.Parent.Parent.CreateTerritoryGui with button.Parent.Parent:WaitForChild("CreateTerritoryGui")
thanks everyone but i figured it out on my own
fyi, there is *=, +=, %=, -=, /=, ..=, operators which to the same thing as value = value + value2