Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't my Screen GUI show up when i press a button is my script wrong?

here's my script

GUI = game.StarterGui.ScreenGui.TextBox.Visible

function onClick()
GUI = true
wait(5)
GUI = false
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

3 answers

GUI = game.Players.PlayerGui.ScreenGui.TextBox.Visible

function onClick()
GUI = true
wait(5)
GUI = false
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

this will make the gui visible for 5 seconds, you dont change startergui because startergui is just the gui that will give players their guis, instead change player.playergui since thats what the players will see

Original Code

So the errors that I can locate is imply the error on the first line

GUI = game.StarterGui.ScreenGui.TextBox.Visible--here

function onClick()
GUI = true
wait(5)
GUI = false
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

The problem with it is you are trying to change the GUI in StarterGui which means it won't affect the player as when playing the game their GUI is in a different location.

Changed Code

So in order to correct this you will need to fix where GUI is pointing but there is a small problem. In order to get the Players GUI you need to get the player first which cant be done where the GUI line currently is so lets move it to the correct place

function onClick(player)--add player so we can so who clicked the block from click detector
GUI = player.PlayerGui.ScreenGui.TextBox.Visible--this is the shorter way to write this

GUI = true
wait(5)
GUI = false
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

Now hopefully that will function as you intended it too I would also recommend adding a debounce so players can't spam the system

try this, and put the gui in replicated storage

gui = game:GetService("ReplicatedStorage").ScreenGui.TextBox
active = false

function onClick()
if active == false then
	active = true -- to prevent spamm
	gui.Visible = true
	wait(5)
	gui.Visible = false
	active = false -- to make it be able to run again
end
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

2 comments

0

why would he put it somewhere else than startergui, this is just stupid since it cant be used

0

he can easily just clone the gui into the players gui. Don't see how this is stupid in anyway, lol?

This discussion is preserved as it was. New answers, comments, and votes are closed.