✓ Accepted answer
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()
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
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
Event:FireClient(player)
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)
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)