this script is in StarterPlayerScripts and it stop printing/working when a player die
-- { VARIABLES } --
local Player = game.Players.LocalPlayer
local Character :Model = Player.Character or Player.CharacterAdded:Wait()
local Humanoid :Humanoid = Character:FindFirstChild("Humanoid") or Character:FindFirstChild("Humanoid"):Wait()
local Alive = false
-- { FUNCTIONS } --
-- { CORE GAME CODE } --
Humanoid.StateChanged:Connect(function(_,after)
if after == Enum.HumanoidStateType.Dead then
Alive = false
task.wait(2)
print(Alive) -- stops printing when a player die
else
Alive = true
end
print(Alive) -- stops printing when a player die
end)
if you donot understand what i mean copy this script and add it in local script and then run the game and move it will output true which is the value of variable { Alive } if you resetted your character it will stop outputting
Hello. I think that I know how it should be fixed. Look at the edited code below:
-- { VARIABLES } --
local Player = game.Players.LocalPlayer
local Character :Model = Player.Character or Player.CharacterAdded:Wait()
local Humanoid :Humanoid = Character:FindFirstChild("Humanoid") or Character:FindFirstChild("Humanoid"):Wait()
local Alive = false
-- { FUNCTIONS } --
-- { CORE GAME CODE } --
Humanoid.StateChanged:Connect(function(_,after)
if after == Enum.HumanoidStateType.Dead then
Alive = false
task.wait(2)
print(Alive) -- stops printing when a player die
else
Alive = true
end
print(Alive) -- stops printing when a player die
end)
-- To fix the script, we need to
-- re-declare character and humanoid
-- every time when player dies
Player.CharacterAdded:Connect(function(character)
Character = character
Humanoid = Character:FindFirstChild("Humanoid") or Character:FindFirstChild("Humanoid"):Wait()
end)
thanks but when i use it the same bug happen it works well until i die and then it stops printing true whenever i move/jump can you try this code in roblox studio and reset your character and then move?
i want to know if this proplem happens to me only and thanks
-- { VARIABLES } --
local Player = game.Players.LocalPlayer
local Alive = false
Player.CharacterAdded:Connect(function()
local Character :Model = Player.Character
local Humanoid :Humanoid = Character:FindFirstChild("Humanoid") or Character:FindFirstChild("Humanoid"):Wait()
local Alive = false
Humanoid.StateChanged:Connect(function(_,after)
if after == Enum.HumanoidStateType.Dead then
Alive = false
task.wait(2)
print(Alive)
else
Alive = true
end
print(Alive)
end)
end)