#Refresh a Gui after player death

23 messages · Page 1 of 1 (latest)

narrow monolith
#

hello, i have a viewport frame that display the player but when he dies there is nothing in the gui, please how to fix this ?

umbral glen
#

You should show the scripts and the explorer

narrow monolith
narrow monolith
#

@umbral glen

pale hollowBOT
#

studio** You are now Level 5! **studio

narrow monolith
#
local viewport = script.Parent
local char = game:GetService("Players").LocalPlayer.Character
local cam = Instance.new("Camera",viewport)

game:GetService("RunService").RenderStepped:Connect(function()
    for i,v in pairs(viewport.Character1:GetDescendants()) do
        v:Destroy()
    end

    for i,v in pairs(char:GetChildren()) do
        local v2 = v:Clone()

        if v2:IsA("Script") or v2:IsA("LocalScript") or v2:IsA("ModuleScript") or v2:IsA("Sound") then
            v2:Destroy()
        else
            v2.Parent = viewport.Character1
            if v2:IsA("Humanoid") then
                v2.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
            end
        end
    end

    viewport.CurrentCamera = cam
    cam.CFrame = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5) * CFrame.Angles(0,math.rad(180),0)
#

in a localscript

south sluice
#

@narrow monolith try listening to the player.CharacterRemoving event, it shows nothing because the character gets deleted and a new one gets created, on death.

narrow monolith
south sluice
narrow monolith
#

Yes

#

It is

south sluice
# narrow monolith It is

Then try adding your code in a listener for player.CharacterRemoving.
You basically do:

game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function(character)
— Your code 
end```
You also don’t need to define a char variable as it is provided by the connection/listener.
narrow monolith
#

Okay thx trying this tomorrow

narrow monolith
# south sluice Then try adding your code in a listener for player.CharacterRemoving. You basica...
game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function(character)

    local viewport = script.Parent
    local char = game:GetService("Players").LocalPlayer.Character
    local cam = Instance.new("Camera",viewport)

    game:GetService("RunService").RenderStepped:Connect(function()
        for i,v in pairs(viewport.Character1:GetDescendants()) do
            v:Destroy()
        end

        for i,v in pairs(char:GetChildren()) do
            local v2 = v:Clone()

            if v2:IsA("Script") or v2:IsA("LocalScript") or v2:IsA("ModuleScript") or v2:IsA("Sound") then
                v2:Destroy()
            else
                v2.Parent = viewport.Character1
                if v2:IsA("Humanoid") then
                    v2.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
                end
            end
        end

        viewport.CurrentCamera = cam
        cam.CFrame = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5) * CFrame.Angles(0,math.rad(180),0)
    end)
end)

thx this work but only when the player die

#

how can i fix this?

narrow monolith
#

(The gui is on when the player join)

south sluice
#

thx this work but only when the player die
When does it not work?
@narrow monolith

narrow monolith
south sluice
narrow monolith
#

(And sorry if my english is a bit bad, tell me if u need me to explain something)

south sluice
#

@narrow monolith are you sure that your cam CFrame is correct?