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

whenever i die my death gui doesn't show up, help?

Asked by 2 years ago

this is a normal script

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Huminoid = char.Humanoid

if Huminoid.Health == 0 then
    Random.new(1,4)
    if Random == 1 then
        script.Parent.Text = "Yuo Died lol"
    end
    if Random == 2 then
        script.Parent.Text = "Today is not your lucky day"
    end
    if Random == 3 then
        script.Parent.Text = "You = Deth"
    end
    if Random == 4 then
        script.Parent.Text = "Did somebody order pizza hut?"
    end
    script.Parent.Visible = true
    script.Parent.Parent.Frame.Visible = true
end

1 answer

Log in to vote
0
Answered by 2 years ago

There are 2 issues here:

You're using a Server-Side script (normal script) to toggle the Frame and edit the TextLabel, GuiObjects can only be toggled/edited by LocalScripts since they are only Client-Side (if the script actually worked it would show the Gui when ANY player died, since its editing the Gui for everyone on the server).

Instead of using an if statement you should use Humanoid.Died event, this fires everytime the player dies, so it is basically the same thing you were trying to achieve with the statement:

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            -- Code Here
        end)
    end)
end)

Although you would need to use a Remote Event or Remote Function (your choice) in order to communicate to the player's PlayerGui, since it can't be accessed by Server-Sided scripts:

local Event = game.ReplicatedStorage.ShowDeathScreen --"ShowDeathScreen" is the name I gave it

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            Event:FireClient(player) --"FireClient()" is used on Remote Events, so I'm using one here but you can use a Remote Function
        end)
    end)
end)

You could use player to refer to PlayerGui but since this has to be in a LocalScript you can put the LocalScript inside the TextLabel:

local Event = game.ReplicatedStorage.ShowDeathScreen

Event.OnClientEvent:Connect(function(player)

    local Random = Random.new(1,4) --Made the Random number a local variable for simplicity
    if Random == 1 then
        script.Parent.Text = "Yuo Died lol"
    end
    if Random == 2 then
        script.Parent.Text = "Today is not your lucky day"
    end
    if Random == 3 then
        script.Parent.Text = "You = Deth"
    end
    if Random == 4 then
        script.Parent.Text = "Did somebody order pizza hut?"
    end
    script.Parent.Visible = true
    script.Parent.Parent.Frame.Visible = true
end)
Ad

Answer this question