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

GUI disappears upon death?

Asked by 6 years ago

I have my local script in starterplayerscripts set to make a GUI and put it in playerGUI. Everytime the Character dies, the gui goes away. How do I make it so the GUI stays or just reappears when the player respawns?

local player = game.Players.LocalPlayer
local gui = Instance.new('ScreenGui',player.PlayerGui)
local frame = Instance.new('Frame',player.PlayerGui)
local textlbl = Instance.new('TextLabel',player.PlayerGui)
local health = Instance.new('IntValue',player)

-----------------------------------------------------------------------------------------------------------------

gui.Name = 'HP'
frame.Name = 'HlthPt'
frame.Parent = player.PlayerGui.HP
textlbl.Parent = player.PlayerGui.HP.HlthPt

health.Name = 'health'
health.Value = 250

frame.Size = UDim2.new(0,250,0,23)
frame.Position = UDim2.new(0.705, 0,0.919, 0)
frame.BackgroundColor3 = Color3.new(0,0,0)

textlbl.Size = UDim2.new(0,250,0,23)
textlbl.Position = UDim2.new(0.001, 0,0.004, 0)
textlbl.BackgroundColor3 = Color3.new(0,198,0)
textlbl.Text = player.health.Value.. '' .. '/250'
player.health.Changed:connect(function()
    textlbl.Size = UDim2.new(0,player.health.Value,0,23)
    textlbl.Text = player.health.Value..''..'/250'
    if player.health.Value <= 166 and player.health.Value >= 83 then
        textlbl.BackgroundColor3 = Color3.new(217,217,0)
    elseif player.health.Value <= 83 then
        textlbl.BackgroundColor3 = Color3.new(227,0,0)
    else
        textlbl.BackgroundColor3 = Color3.new(0,198,0)
    end
    if player.health.Value > 250 then
        player.health.Value = 250
    elseif player.health.Value < 0 then
        player.health.Value = 0
    end
    if player.health.Value <= 0 then
        player.Character.Head:remove()

    end
end)
0
there is an option in screenguis called 'resetonspawn', disable it User#20388 0 — 6y
0
ok User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by
green271 635 Moderation Voter
6 years ago

ScreenGUIs have a property called ResetOnSpawn. Somewhere in your code, you should put: gui.ResetOnSpawn = true

Ad
Log in to vote
0
Answered by 6 years ago

The StarterGui has a property called ResetPlayerGuiOnSpawn. If this property is set to false, then the GUIs will not be removed or reset when the character dies.

Hope that helped

Answer this question