UI dosen't show up after respawn

Idk, why does this not work correctly? I want to show to player a GUI after the respawned but it’s not working, even the print("broken") doesn’t show up.

LocalScript - Roblox Studio 18.02.2022 18_20_10_LI
EDIT: I moved the Local Script to the StarterPlayerScripts, but its still not working.

local Menu = game.Players.localPlayer.PlayerGui.StaminaBarGui
local Players = game:GetService("Players")

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	Player.CharacterAdded:Wait()
	Menu.Enabled = true
	print("broken")
end)

2 Likes

You should replace “wait(5)” by Player.CharacterAdded:Wait()

1 Like
player.CharacterAdded:Connect(function() -- fires every time the character gets added, even when respawned.
    Menu.Enabled = true
    print("Worked?")
end)
1 Like

Make sure the ResetOnSpawn property of the ScreenGui is set to false

1 Like

set ResetOnSpawn property to false

1 Like

I think what’s happening is that the localscript is getting deleted before it can print. Try removing the wait(5), or as others have said set the ResetOnSpawn property of the ScreenGui to false.

A player’s PlayerGui folder is emptied when their character’s humanoid dies.

1 Like

Maybe you didnt disabled the Property ResetOnSpawn on the ScreenGui.

4 Likes

I can’t turn ResetOnSpawn on because I have another local script in the GUI that needs to that ResetOnSpawn is on

Look at the post again because I updated it with new information.

I updated the post! Please see the new information related to this issue.

1 Like

Well I think i found the problem.

Try this out:

local Players = game:GetService("Players")

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	Player.CharacterAdded:Wait()
	local Menu = game.Players.localPlayer.PlayerGui.StaminaBarGui
	Menu.Enabled = true
	print("not broken")
end)

Basically why it didnt work is because you defined the Menu before the player died, so the ScreenGui Resets if you die and the Menu doesnt exist anymore because ResetOnSpawn is turned on. If you defined the Menu after the Player.CharacterAdded:Wait() then it will use the new ScreenGui .

I hope u understand im not best english speaker. i hope it even works lol

1 Like

I get an error: StaminaBarGui is not a valid member of PlayerGui “Players.SMHerobrine.PlayerGui”

1 Like

Try add a :WaitForChild()

local Menu = game.Players.localPlayer.PlayerGui:WaitForChild("StaminaBarGui")

It is now working, so thank you!

Great! If you have anymore issues don’t be afraid to make another post!

1 Like