local isPlayerDead = false
Citizen.CreateThread(function()
while true do
if IsPlayerDead(PlayerId()) then
if isPlayerDead == false then
isPlayerDead = true
SendNUIMessage({
setDisplay = true
})
end
else
if isPlayerDead == true then
isPlayerDead = false
SendNUIMessage({
setDisplay = false
})
end
end
Citizen.Wait(100)
end
end)
But the problem is that the message is showing even the player is alive. I want it to show just for dead people. What is wrong ?
Hmm you naming seems confusing, thus making it hard to comprehend.
Changed some things around and added some verbose comments to help you understand what might be going on.
local isDeathScreenShowing = false
Citizen.CreateThread(function()
local player = PlayerPedId()
while true do
-- Is the player dead or alive?
local isPlayerDead = IsPlayerDead(player)
--If dead, then...
if isPlayerDead then
-- And we are not showing the death screen...
-- Then show the death screen
if isDeathScreenShowing == false then
isDeathScreenShowing = true
SendNUIMessage({setDisplay = true})
end
-- Else if the player is not dead.
else
--And we are currently showing the death screen...
-- Then hide it.
if isDeathScreenShowing then
isDeathScreenShowing = false
SendNUIMessage({setDisplay = false})
end
end
Citizen.Wait(100)
end
end)