Humanoid.Health = 0 problem

So I made this script you can ignore the part in the middle, but at the end where the players health is set to 0 nothing happends and the printing around it does print. I’ve tried mulitple ways to kill the player already.

game.Players.PlayerAdded:Connect(function(player)
	
	local values = Instance.new("Folder")
	values.Name = "Values"
	values.Parent = player
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			local newStage = player.leaderstats.Stage.Value + 1
			player.leaderstats.Stage.Value = newStage
			
			player.CharacterAdded:Wait()
			
			local text = "Stage "..newStage..": "..stageNames[newStage]
			
			wait(2)

			textRemote:FireClient(player, text)
			
			if newStage == 7 then
				playSoundRemote:FireClient(player, voiceStage7)
				
				for i,v in pairs(replicatedStorage.Rooms.Room7:GetChildren()) do
					local newZombie = v:Clone()
					newZombie.Parent = workspace.Rooms.Room7.ZombieFolder
				end
				
				local newAgeValue = Instance.new("IntValue")
				newAgeValue.Name = "Age"
				newAgeValue.Parent = player.Values
				
				for i = 1,76,1 do
					wait(0.1) -- change back to 1.2, 1.3, 1.4 or 1.5
					
					newAgeValue.Value += 1
					
					if player.leaderstats.Stage.Value == 8 and i < 75 then
						player.CharacterAdded:Wait()
						
						wait(2)
						
						deathScreenRemote:FireClient(player)
					end
				end
				print("Done") -- prints
				wait(10)
				print("Done2") -- prints
				character:FindFirstChild("Humanoid").Health = 0 -- here it does nothing
			end
		end)
	end)
end)

Try

character:FindFirstChild("Humanoid").Health -= character:FindFirstChild("Humanoid").Health

and see what is does. It doesn’t make much of a difference, I just want to see if it would work.

Why did someone like my deleted post :skull:

lol idk

abcdefghijklmn

The problem is because you can’t set Humanoid.Health in a Humanoid.Died event.

I tested it out and yeah, I’m right.

How would I message the server from that point in the script to kill the player?

Make a BindableEvent in ServerStorage and name it SetPlayerHealth.

-- Script 1
local bindableEvent = game:GetService("ServerStorage"):WaitForChild("SetPlayerHealth")

game.Players.PlayerAdded:Connect(function(player)
	
	local values = Instance.new("Folder")
	values.Name = "Values"
	values.Parent = player

	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			local newStage = player.leaderstats.Stage.Value + 1
			player.leaderstats.Stage.Value = newStage
			
			player.CharacterAdded:Wait()
			
			local text = "Stage "..newStage..": "..stageNames[newStage]
			
			wait(2)

			textRemote:FireClient(player, text)
			
			if newStage == 7 then
				playSoundRemote:FireClient(player, voiceStage7)
				
				for i,v in pairs(replicatedStorage.Rooms.Room7:GetChildren()) do
					local newZombie = v:Clone()
					newZombie.Parent = workspace.Rooms.Room7.ZombieFolder
				end
				
				local newAgeValue = Instance.new("IntValue")
				newAgeValue.Name = "Age"
				newAgeValue.Parent = player.Values
				
				for i = 1,76,1 do
					wait(0.1) -- change back to 1.2, 1.3, 1.4 or 1.5
					
					newAgeValue.Value += 1
					
					if player.leaderstats.Stage.Value == 8 and i < 75 then
						player.CharacterAdded:Wait()
						
						wait(2)
						
						deathScreenRemote:FireClient(player)
					end
				end
				print("Done") -- prints
				wait(10)
				print("Done2") -- prints
				bindableEvent:Fire(0)
			end
		end)
	end)
end)

-- Script 2 (Server Script)
local bindableEvent = game:GetService("ServerStorage"):WaitForChild("SetPlayerHealth")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        bindableEvent.Event:Connect(function(health)
            character:FindFirstChildOfClass("Humanoid").Health = health
        end)
    end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.