That doesn't work

a = 1
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()
plr.Character.Humanoid.Died:Connect(function()
    print("alo")
    plr.Character.Humanoid.WalkSpeed = a+11

end)
    end)

That script doesn’t print alo twice. Because It ignores when humanoid died second time. Why does this happen?
This is a script in workspace also there is no errors.

You have to use CharacterAdded.Connect.
CharacterAdded:Wait() simply yields the script until the player spawns in, and then connects the Humanoid.Died event of the current humanoid. When the Player dies and respawns, a new Humanoid gets created which does not keep the new connection.

You can fix this easily by just replacing plr.CharacterAdded:Wait() with plr.CharacterAdded:Connect(function(Character), replace Plr.Character.Humanoid with Character:WaitForChild'Humanoid' and then just add another end) to the end of the script!

1 Like

You need to get the new character object. Try something like this:

local a = 1

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)

		local hum = char:WaitForChild("Humanoid", 5)
		if hum then
			hum.WalkSpeed = (a + 11)
		end
	end)
end)

EDIT: I removed the .Died event since CharacterAdded fires after a character is added – meaning that you either just joined the game or died.

1 Like