Why does my script work with false values but not true values

i have a script for a game that im making but when i try to test it it doesnt work,

if wframe1.Visible == true and wframe4.Visible == true and wframe7.Visible == true then --when i replaced the ==true values with = false, it worked but not as intended--
	script.Parent.Stick.Visible = true
	script.Parent.Stick.MouseButton2Click:Connect(function()
		script.Parent.Stick.Visible = false
		game.Workspace.Stick.Value = game.Workspace.Stick.Value + 1
		game.Workspace.Wood.Value = game.Workspace.Wood.Value - 3
		wframe1.Visible = false
		wframe4.Visible = false
		wframe7.Visible = false
	end)
end
4 Likes

Can you show us the output when both the true and false values are used? Also, you should implement s few prints in your script to check if the code even reaches that point.

2 Likes

nothing was inputted with the true values, but with the false values the print was inputted
image

2 Likes

Is the script for some type of gui? Also, you shouldn’t use game.Workspace in your script, just use “workspace”/“Workspace”!

3 Likes

yea its for a crafting gui
image

2 Likes

Nice, in that case make sure that you’re referencing your gui through the player’s playerGui, as at runtime, the gui gets replicated into playerGui, and only there will it update.

that didnt work, i changed my code to reference the playergui

1 Like

What I would do to try and debug this, is add a print like so;

print(wframe1, wframe4, wframe7)

In the output this should print the instance and clicking them will bring you to the instance in the explorer. Here you can check to see if your variables are set up correctly. If this does not clarify anything, please share more code and screenshots so we can see where the issue resides.

1 Like

the issue is within this part of the code

if wframe1.Visible == true and wframe4.Visible == true and wframe7.Visible == true then

nothing gets printed past it

1 Like

im thinking the issue is because i have GuiCollisionService. and i dont think it registers, like for example i have a gui that if another gui touches it, it becomes visible

yep just tested it, if i have the gui visible from the start its all good. the gui collision service kinda breaks some things. i dont know how to fix it

after a few tests its not the issue of the gui collition, its just nothing gets executed after having

if wframe1.visible == true then
       stick.visible == true
end

the stick for some reason just doesnt pop up, matter of fact nothing after the if statment

Post attempt #2:
I might see where it goes wrong.
Your code goes as follows:

if <wframe.Visible == false conditions> then
   script.Parent.Stick.Visible = true
   script.Parent.Stick.MouseButton2Click:Connect(function()
      <code>
   end)
end

Code runs from top to bottom, line by line, so what it is doing now is as soon as there is a change in wframe.Visible and all the conditions are met, it will continue. Then it hits the MouseButton2Click. Is the mouse button not being clicked the millisecond after the wframe conditions are passed, then it will count as a no and break the code. Instead, swap them around, since the timeframe of a buttonclick is not constant, whereas the wframe visiblity is.

script.Parent.Stick.MouseButton2Click:Connect(function()
   print(wframe1.Visible, wframe4.Visible, wframe7.Visible) --//debugging purposes only, to check if conditions are equal to the conditions needed to be met
   if wframe1.Visible == false and wframe4.Visible == false and wframe7.Visible == false then
      <code>
   end
end)

If this works, I do not know yet, but this will at the least run the code in the box.