I tried to make a code that if the player humanoid dies then it connect a function that makes a GUI visible with a death message, but it didn't worked. I did something wrong? (And the player didn't teleport to the part on workspace) Code below:
local prl = game.Players.LocalPlayer
local char = prl.Character or prl.CharacterAdded:Wait()
local lightning = game:GetService("Lighting")
local blur = lightning.Blur
local guideath = prl.PlayerGui:WaitForChild("TelaDeMorte")
char.Humanoid.Died:Connect(function()
guideath.TExto.Visible = true
for i= 1,10 do
task.wait(.1)
guideath.TExto.TextTransparency -= .1
end
task.wait(6)
char:SetPrimaryPartCFrame(workspace.SpawnPoint.CFrame)
guideath.TExto.TextTransparency = 1
guideath.TExto.Visible = false
end)
The character is not the same anymore after a respawn. So you'd have to subscribe to the CharacterAdded event instead, like this:
local prl = game.Players.LocalPlayer
prl.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function()
local guideath = prl.PlayerGui:WaitForChild("TelaDeMorte")
guideath.TExto.Visible = true
for i= 1,10 do
task.wait(.1)
guideath.TExto.TextTransparency -= .1
end
task.wait(6)
char:SetPrimaryPartCFrame(workspace.SpawnPoint.CFrame)
guideath.TExto.TextTransparency = 1
guideath.TExto.Visible = false
end)
end)