Gui button not working?

So i’m making an arcade in my game, and basically im making a gui game thingy, and i’m probably gonna post more bc im bad at scripting, but the gui isn’t showing up bc “RedButton1 is not a valid member of Workspace” When It clearly is .__.



game.Workspace.RedButton1.ClickDetector.MouseClick:Connect(function()
 -- 
 if player.PlayerGui.MiniGame.Game.Visible == false then
 --
  player.PlayerGui.MiniGame.Game.Visible = true
 else
  player.PlayerGui.MiniGame.Game.Visible = false
 
 end 
end)

The reason your script doesn’t work is because you never defined “player.” Player will be the parameter in the .MouseClick event, so you should change function() to function(player).

Also, to make your script easier, you can just do this (not required):

game.Workspace.RedButton1.ClickDetector.MouseClick:Connect(function(player)
   player.PlayerGui.MiniGame.Game.Visible = not player.PlayerGui.MiniGame.Game.Visible
end)
1 Like

I tried both of the things you suggested and its giving me the same thing in the input “RedButton1 is not a valid member of Workspace”

Well then that means exactly what it says, RedButton1 isn’t something in the workspace so make sure you’re talking about the correct part.

I would suggest using a remote function and firing it to the client.

Ive renamed it multiple times and copy and pasted the name, so idk

Then try game.Workspace:WaitForChild(“RedButton1”). If that doesn’t work either, then you simply don’t have anything in the workspace called “RedButton1”


im geniuenly confused, am I stupid, or is Lua stupid

try waitforchild like I mentioned above

Try doing game.Workspace[“RedButton1”]

In the workspace something is wrong make sure that the path is game.workspace and not in any other folder or another object’s child

game.Workspace can be used, but I recommend just using workspace. Anyways,

Make sure that no other script would be destroying the part.
Try checking in Explorer for the part when you Play.

You may have workspace.StreamingEnabled set to true. With StreamingEnabled, parts/models don’t replicate to your client until you are near them. I wouldn’t recommend disabling it if you have a large detailed map though, as keeping it enabled improves join times and can reduce lag.

Also, be careful accessing that by name, because a player named “RedButton1” could potentially break your game. Consider “_RedButton1” instead.

Make sure you don’t have another part with the same name.

There’s a chance your script isn’t compatible to reach parts like that. I’m not good at scripting, but I sometimes get errors saying something isn’t there when clearly it was . Try using a Local Script for this. If your script is in StarterGui which I suppose it isn’t then that would probably be the problem here. Anyways Good Luck and Keep Learning!

try adding a waitforchild

workspace:WaitForChild("RedButton1"):WaitForChild("ClickDetector").MouseClick:Connect(function(player)
   player.PlayerGui.MiniGame.Game.Visible = not player.PlayerGui.MiniGame.Game.Visible
end)
1 Like

same problem, its not in a folder and its spelled exactly how its supposed to. the parent is still workspace

thaNK YOU so MUCHHCKDJSHGKSDJFHGJKLSD
IVE HAD A lot of wifi problems so working in studio has been FRUSTRATING, and this WORKED. T H A N K Y O U MR. SQUAREPAPYRUS