Need help with GUI script

You can write your topic however you want, but you need to answer these questions:

I want to make it so that whenever the user presses their space bar, the ui becomes invisible.

The issue, is that my script won’t work, but doesn’t even return any errors.
The script was working before. But now it doesn’t seem to work, I’ve made sure it’s enabled, and when the gui IS shown, I check, and it’s Visible property is ticked.

local mouse = game.Players.LocalPlayer:GetMouse()
while script.Parent.Visible == true do
	wait(0.01)
	print("wait")
	mouse.KeyDown:connect(function(key)
		if key:byte() == 32 then
			print("off")
			script.Parent.Visible = false
		end
	end)
end

Btw it doesn’t print anything

1 Like

Before creating the loop, can you print what the value of script.Parent.Visible is?

1 Like

Screenshot 2024-06-27 at 8.06.12 AM
It marks it as false.

1 Like

Then the loop isn’t running. While loops stop and never run again if the condition is false.

1 Like
script.Parent.Visible = true
game.UserInputService.InputBegan:Connect(function(i ,gpe)
   if gpe then return end
   if i.KeyCode == Enum.KeyCode.Space then
      script.Parent.Visible = not script.Parent.Visible
   end
end)
2 Likes

It’s better to use UserInputService, as shown above

1 Like

basic scripting :skull:

(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)

2 Likes

Wait it didn’t even work, is this supposed to be in a ServerSided script?

1 Like

local script lil bro

(aaaaaaaaaaaa)

bud it’s not working, I changed it to this (still doesn’t work):

‘’'script.Parent.Visible = false
game.UserInputService.InputBegan:Connect(function(i ,gpe)
if gpe then return end
if i.KeyCode == Enum.KeyCode.Space then
script.Parent.Visible = true
end
end)``

whered u place the script

it must be below ur ui

Screenshot 2024-06-27 at 8.11.21 AM
It is below.

huh

did it work first time?

(aaaaa)

No, your script never worked. My orginial script WAS working, but even when I didn’t change it, now it doesn’t work. I remember it working last night and now it doesn’t work.

uhhhhhhhhhhhh

try this code and lmk the output:


script.Parent.Visible = true
game.UserInputService.InputBegan:Connect(function(i ,gpe)
   if gpe then return end
print("yes")
   if i.KeyCode == Enum.KeyCode.Space then
print("yay")
      script.Parent.Visible = not script.Parent.Visible
print(script.Parent.Visible)
   end
end)

1 Like


wait whatt, it’s not changing the GUI, also I changed it to:

script.Parent.Visible = false
game.UserInputService.InputBegan:Connect(function(i ,gpe)
	if gpe then return end
	print("yes")
	if i.KeyCode == Enum.KeyCode.Space then
		print("yay")
		script.Parent.Visible = true
		print(script.Parent.Visible)
	end
end)

No it worked. Nevermind, sorry I was confused.

1 Like

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