Output gives error after setting ScreenGui to false after amount of time

I have a problem here, so I’m struggling to make the ScreenGui’s visibility to false by doing ScreenGui.Enabled = false after a group of script has been finished. I’ll show you the following code which you will understand.

So over here I’m trying to create a scary atmosphere to the player by sending messages using ScreenGui, Frame and TextLabel! But when I want the ScreenGui to be invisible after a certain amount of time it keeps giving me this error.

image

Do any of you know a better way I could do this, also I think it might link to this.

image

So like, I want to set the screengui to false at the end even though its visible at the start.

local Player = game.Players.LocalPlayer
local ScreenGui = Player.PlayerGui:WaitForChild("ScreenGui")

if ScreenGui then
    --[[ Too lazy to copy the text code so just put it here ]] --

    ScreenGui.Enabled = false
end
2 Likes

ScreenGui is not a property. If you want to disable it do ScreenGui.Enabled = false
Also use a localscript for GUI like tasks. Don’t use a script for changing the GUI.

If you gonna switch to a local script you have to only keep the variable t and the code for changing and waiting. Also, it would not work since game.Players.PlayerAdded is a event and not a property.

3 Likes

I didn’t even notice the fact that it was a Script and not a local, good catch.

1 Like
local t = script.Parent
if game.Players.PlayerAdded:Connect(function(player)
    <your code>
    player.PlayerGui.ScreenGui.Enabled = false
end)

this should work with a normal script
but you should work with localscripts for guis

Oh right, but do you know when to use a local script or a script, like for example what are they good for
and what can they do mainly.

Oh, right. I’ve just encountered my mistakes and resolved them.

  • Use a LocalScript

  • Use the instance WaitForChild because obviously the player gui doesnt exist until
    I play the game.

I really understood it, thanks for helping! :slight_smile:

1 Like

You want to use a local script for everything on the client. So GUI for example. Although you should not rely on a local script to much as a exploiter can easily modify the local scripts

1 Like

Oh right! So local scripts are appropriate for when your interacting with the client. Understood, thanks for the help.