Script not able to change gui visibility

I have a gui that needs to run a script inside of it while the player is dead, so I need resetonspawn to be false, however I don’t want the gui to be visible when the player dies so what I did was in starter player scripts I added a script that made the gui not visible when the player died and respawned but, the gui is still visible after the player dies. I checked the value and the gui says its visibility is set to false even though its still visible.

Can you show the script in question?

local screen = game.StarterGui.Menu
local frame = screen.Frame
game.Players.LocalPlayer.CharacterAdded:Connect(function()
	screen.Open.Visible = true
	frame.Visible = false
	frame.ScrollingFrame.Visible = false
end) 

Im probably missing something simple.

You’re accessing StarterGui instead of PlayerGui.
Replace game.StarterGui with game.Players.LocalPlayer.PlayerGui
You’re also not using the Died event to check when the player dies, so this won’t work nonetheless.

2 Likes

I would recommend making a script inside of the gui (a localscript) that sets the visible property to true when the died event on the localplayer’s humanoid is fired, and then simply set the visible property to false once the character is loaded.

Let me know if you need help scripted it.

1 Like

you have to do it in player gui instead

local screen = game.Players.LocalPlayer.PlayerGui:WaitForChild("Menu")
local frame = screen.Frame
game.Players.LocalPlayer.CharacterAdded:Connect(function()
	screen.Open.Visible = true
	frame.Visible = false
	frame.ScrollingFrame.Visible = false
end)

@ZeInventor

1 Like

That should work. did you try it?

It’ll make it invisible when the player loads, not when the player dies.

Use the event:

local plr = game.Players.LocalPlayer

plr.Character.Humanoid.Died:Connect(function()

end)

Set the property to true (visible to true) inside that codeblock, and your other code should make it invisible when they respawn. You could also just use wait(5) or whatever your respawntime is set to as well.

1 Like

If the character or the humanoid is nil, your code will error.

local player = game.Players.LocalPlayer
local screen = player.PlayerGui:WaitForChild("Menu")
local frame = screen.Frame
player.CharacterAdded:Connect(function(character)
	character:WaitForChild("Humanoid").Died:Connect(function()
		screen.Open.Visible = true
		frame.Visible = false
		frame.ScrollingFrame.Visible = false
	end)
end)
1 Like

I apologize, I didn’t mean to say when the player dies, I’m fine as long as its gone when the player respawns.

1 Like

Ohhh alright. No problem That makes sense.

1 Like