Can I make a while loop start when a player dies? If so how could I?
You can do this … and you have limited time to do whatever before they respawn. Like a blur screen.
humanoid.Died:Connect(function()
end)
If you want to control the entire respawn process you can set Players.CharacterAutoLoads
to false but you’ll need to make a respawn script
Figured you could but never really researched it for anything myself. Depending on what he is doing this may be an easy fix.
This should work
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
while wait() do
if humanoid.Health <= 0 then
print("Humanoid Died")
end
end
Or you could also use a for loop, this will print the amount of iteration and will run 10 times
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
for i = 1, 10, 1 do
print("Died "..i.." times")
wait(0.1)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
plr.Character:WaitForChild("Humanoid").Died:Connect(function()
while true do
wait() -- Always put a wait() in a while loop because it goes so fast studio will crash
-- Code what to do in the while loop
end
end)
end)
That wait() is like saying rs.Heartbeat:Wait(). As fast as possible. You never want that as a loop stall.
task.wait(0.33) is about as low as I ever go. Something like this could use task.wait(1) and work fine.
I like to use rs.Stepped:Wait() as that will not lag out any other part of the program.
local rs = game:GetService("RunService")
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
while rs.Stepped:Wait() do
if humanoid.Health <= 0 then
print("Humanoid Died")
end
end
This should work as Baller said and also not eat up your cycle time.
No I’m very sure Heartbeat is faster, because it’s like every frame or smthing else
And it depends on what whoever made this Topic of " Can I make a while loop start when a player dies?" of how fast he wants it to run
Sorry if you feel offended. Just looking to remove things that will cause errors.