Appearing gui issue

So I want to make a gui disappear and reappear but it don’t work I’m confused I have edited the code for a bit know so I thought to come here.

Code:

local players = game:GetService(“Players”)
local player = players.LocalPlayer

local Frame1 = player.PlayerGui.Base1SolarStatus.SolarFrame

while true do
task.wait(4)
Frame1.Visible = true
task.wait(4)
Frame1.Visible = false
end

The Output says:

Players.3DRobloxGameDev.PlayerGui.Base1SolarStatus.SolarFrame.Script:4: attempt to index nil with ‘PlayerGui’

Here is my explorer

explorer

Just do script.Parent to get the Frame: (should be a localscript)

local Frame1 = script.Parent

while true do
   task.wait(4)
   Frame1.Visible = true
   task.wait(4)
   Frame1.Visible = false
end

Btw, the PlayerGui is nil because you cant use Players.LocalPlayer on the server. Put the script inside a LocalScript instead (so its on the client) to do it like that.

Normal scripts (aka Server code) does not run anywhere beside workspace and ServerScriptService.
To fix your code simply change to a LocalScript

1 Like

It made the entire frame go apart from the one I wanted it to go only go

Edit: I edited the code I originally had and put it in a local script thx thx to @ShyFlooo And added another part on

Well, this is not entirely true, I have in the past had scripts running in a gui text button, to handle clicked events to do things on the server

1 Like