Help me with script

Why this script wont work after someone dies

local RunService = game:GetService("RunService")

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer

local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

while wait() do
	if Character:WaitForChild("HumanoidRootPart"):FindFirstChild("Running").Playing == true then
		if LocalPlayer.InGame.Game.Value == true and LocalPlayer.InGame.CanWalk.Value == false then
				Character:WaitForChild("Humanoid").Health = 0
		end
	
		end
end
game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
      character.Died:Connect(function()
         --Do any script here that will run after a player dies
      end)
   end)
end)

Still dont work any suggestions?

any errors in output? it should work, also try to write game with lovercase g, i’m not sure if it works with “Game”. Try to print something instead of your script after Died event

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(character)
      local Humanoid = character:waitForChild('Humanoid')
      Humanoid.Died:Connect(function()
         --Do any script here that will run after a player dies
      end)
   end)
end)

died is a event of the humanoid not a model

oh ye… right anyway he didn’t send output error so i couldn’t notice

Is this code in a local script?

Because you put the character outside of the loop it wont re-check the character. Try putting it inside the loop like this:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

while wait() do
    local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
	if Character:WaitForChild("HumanoidRootPart"):FindFirstChild("Running").Playing == true then
		if LocalPlayer.InGame.Game.Value == true and LocalPlayer.InGame.CanWalk.Value == false then
			Character:WaitForChild("Humanoid").Health = 0
		end
	end
end
2 Likes