My script Does Not detecting second die of character

I was making a sword fight system but the script doesn’t detecting the second die of character. There is no any errors or any warnings in the console. The character is spawns normally which is not expected. Also doesn’t prints the second die.

local values = script.Parent.values

values.plr1.ready.Changed:Connect(function()
	
	while true do
		
		wait(1)
		
		if values.plr1.ready.Value == true then
			
			if values.countdown.Value < 1 then

				game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild(script.Parent.Name.."plr1").countdown.Text = "maç başlıyor..."
				
				wait(math.random(1,2))
				
				game:GetService("Players"):FindFirstChild(values.plr1.Value).Character:MoveTo(script.Parent.p1.Position)
				
				values.plr1.ready.Value = false
				values.busy.Value = true
				
				script.Parent.scripted.billboard.screen.SurfaceGui.p1.stat.Text = "in match"
				script.Parent.scripted.billboard.screen.SurfaceGui.p1.stat.TextColor3 = Color3.new(0,1,0)
				
				game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild(script.Parent.Name.."plr1"):Destroy()
				local clone = game:GetService("ServerStorage").sf_storage.scoreboard:Clone()
				clone.Parent = game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui
				
				local tool = game:GetService("ServerStorage").sf_storage.Sword:Clone()
				tool.Parent = game:GetService("Players"):FindFirstChild(values.plr1.Value):FindFirstChild("Backpack")
				
				game:GetService("Players"):FindFirstChild(values.plr1.Value).Character.Humanoid.died:Connect(function()

					print("plr1 died")

					values.plr2.kills.Value = values.plr2.kills.Value + 1
					game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild("scoreboard").score2.Text = values.plr2.kills.Value

					game:GetService("Players"):FindFirstChild(values.plr1.Value):LoadCharacter()
					game:GetService("Players"):FindFirstChild(values.plr1.Value).Character:MoveTo(script.Parent.p1.Position)

					local tool = game:GetService("ServerStorage").sf_storage.Sword:Clone()
					tool.Parent = game:GetService("Players"):FindFirstChild(values.plr1.Value):FindFirstChild("Backpack")

				end)
				
			else

				values.countdown.Value = values.countdown.Value - 1
				game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild(script.Parent.Name.."plr1").countdown.Text = values.countdown.Value

			end
			
		end
		
	end
	
end)

Player humanoid are different instance when respawn so you need to Connect Died event again when respawn like this

local values = script.Parent.values

values.plr1.ready.Changed:Connect(function()

	while true do

		wait(1)

		if values.plr1.ready.Value == true then

			if values.countdown.Value < 1 then

				game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild(script.Parent.Name.."plr1").countdown.Text = "maç başlıyor..."

				wait(math.random(1,2))

				game:GetService("Players"):FindFirstChild(values.plr1.Value).Character:MoveTo(script.Parent.p1.Position)

				values.plr1.ready.Value = false
				values.busy.Value = true

				script.Parent.scripted.billboard.screen.SurfaceGui.p1.stat.Text = "in match"
				script.Parent.scripted.billboard.screen.SurfaceGui.p1.stat.TextColor3 = Color3.new(0,1,0)

				game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild(script.Parent.Name.."plr1"):Destroy()
				local clone = game:GetService("ServerStorage").sf_storage.scoreboard:Clone()
				clone.Parent = game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui

				local tool = game:GetService("ServerStorage").sf_storage.Sword:Clone()
				tool.Parent = game:GetService("Players"):FindFirstChild(values.plr1.Value):FindFirstChild("Backpack")
				
				local function SetupDiedEvent()
					game:GetService("Players"):FindFirstChild(values.plr1.Value).Character.Humanoid.died:Connect(function()

						print("plr1 died")

						values.plr2.kills.Value = values.plr2.kills.Value + 1
						game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild("scoreboard").score2.Text = values.plr2.kills.Value

						game:GetService("Players"):FindFirstChild(values.plr1.Value):LoadCharacter()
						game:GetService("Players"):FindFirstChild(values.plr1.Value).Character:WaitForChild("Humanoid") --yield until humanoid is present
						game:GetService("Players"):FindFirstChild(values.plr1.Value).Character:MoveTo(script.Parent.p1.Position)

						local tool = game:GetService("ServerStorage").sf_storage.Sword:Clone()
						tool.Parent = game:GetService("Players"):FindFirstChild(values.plr1.Value):FindFirstChild("Backpack")
						
						SetupDiedEvent()
					end)
				end
				
				SetupDiedEvent()

			else

				values.countdown.Value = values.countdown.Value - 1
				game:GetService("Players"):FindFirstChild(values.plr1.Value).PlayerGui:FindFirstChild(script.Parent.Name.."plr1").countdown.Text = values.countdown.Value

			end

		end

	end

end)
1 Like

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