Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
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

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Log in to vote
-1
Answered by
oSyM8V3N 429 Moderation Voter
4 years ago
Edited 4 years ago

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)

0
why would he put it somewhere else than startergui, this is just stupid since it cant be used Gameplayer365247v2 1055 — 4y
0
he can easily just clone the gui into the players gui. Don't see how this is stupid in anyway, lol? oSyM8V3N 429 — 4y

Answer this question