My script isnt working, any ideas why?

Hi guys, my script isnt working for some reason… I’m new to scripting so i’m not really sure why, could anyone help me?

The part of the script that isnt working:

local function startEvent()
	
	local plr1CurrentKills = 0
	local plr2CurrentKills = 0
	
	local SwordGiver = game.ServerStorage.Sword

	local Sword1 = SwordGiver:Clone()
	local char1 = standingOnArena1Player1.Character
	if char1 then
		local humanoid1 = char1:FindFirstChild("Humanoid")
		
		humanoid1.Died:Connect(function()
			plr2CurrentKills = plr2CurrentKills + 1
			if plr1CurrentKills < 5 then
				if humanoid1 then
					humanoid1.RespawnLocation = game.Workspace.Arena1Team1
					Sword1.Parent = standingOnArena1Player1.Backpack
					humanoid1:EquipTool(Sword1)
				end
			end
		end)		
	end

	local Sword2 = SwordGiver:Clone()
	local char2 = standingOnArena1Player2.Character
	if char2 then
		local humanoid2 = char2:FindFirstChild("Humanoid")
		
		humanoid2.Died:Connect(function()
			plr1CurrentKills = plr1CurrentKills + 1
			if plr2CurrentKills < 5 then
				if humanoid2 then
					humanoid2.RespawnLocation = game.Workspace.Arena1Team2
					Sword2.Parent = standingOnArena1Player2.Backpack
					humanoid2:EquipTool(Sword2)
				end
			end
		end)
	end
end

The whole script:


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

local part1 = workspace.Arena1Player1
local part2 = workspace.Arena1Player2

local team1 = workspace.Arena1Team1
local team2 = workspace.Arena1Team2

local standingOnArena1Player1 = nil
local standingOnArena1Player2 = nil


local RemoteEvent = game.ReplicatedStorage:FindFirstChild("RemoteEvent")

local function startEvent()
	
	local plr1CurrentKills = 0
	local plr2CurrentKills = 0
	
	local SwordGiver = game.ServerStorage.Sword

	local Sword1 = SwordGiver:Clone()
	local char1 = standingOnArena1Player1.Character
	if char1 then
		local humanoid1 = char1:FindFirstChild("Humanoid")
		
		humanoid1.Died:Connect(function()
			plr2CurrentKills = plr2CurrentKills + 1
			if plr1CurrentKills < 5 then
				if humanoid1 then
					humanoid1.RespawnLocation = game.Workspace.Arena1Team1
					Sword1.Parent = standingOnArena1Player1.Backpack
					humanoid1:EquipTool(Sword1)
				end
			end
		end)		
	end

	local Sword2 = SwordGiver:Clone()
	local char2 = standingOnArena1Player2.Character
	if char2 then
		local humanoid2 = char2:FindFirstChild("Humanoid")
		
		humanoid2.Died:Connect(function()
			plr1CurrentKills = plr1CurrentKills + 1
			if plr2CurrentKills < 5 then
				if humanoid2 then
					humanoid2.RespawnLocation = game.Workspace.Arena1Team2
					Sword2.Parent = standingOnArena1Player2.Backpack
					humanoid2:EquipTool(Sword2)
				end
			end
		end)
	end
end

RemoteEvent.OnServerEvent:Connect(function() -- if any player presses the play button, executes event
	if standingOnArena1Player2 ~= nil and standingOnArena1Player1 ~= nil then
		--Hide playbutton gui
		standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = false
		standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = false
		--Teleports
		workspace[standingOnArena1Player1.Name].HumanoidRootPart.CFrame = CFrame.new(team1.Position.X,team1.Position.Y,team1.Position.Z)
		workspace[standingOnArena1Player1.Name].HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad(90), 0)
		workspace[standingOnArena1Player2.Name].HumanoidRootPart.CFrame = CFrame.new(team2.Position.X,team2.Position.Y,team2.Position.Z)
		workspace[standingOnArena1Player2.Name].HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad(270), 0)
		local gameRunning = true
		startEvent() -- triggers function
	end
end)


-----------------------------------------------------

--				PART1 Events				 --

-----------------------------------------------------

-- Touched functions [Events now set each part that was touched to the players name instead of the opposite button]

part1.Touched:Connect(function(TouchedPart) -- Touched

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player1 == nil then -- Check if not standing and if not occupied

			part1.BrickColor = BrickColor.new("Teal") -- Set color
			standingOnArena1Player1 = Player
		end	
	end
end)

part1.TouchEnded:Connect(function(TouchedPart)

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player1 ~= nil then -- Check if standing and is occupied
			if  standingOnArena1Player1.PlayerGui.ScreenGui.Enabled == true then
				standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = false
			end
			part1.BrickColor = BrickColor.new("Smoky grey") -- Set color
			standingOnArena1Player1 = nil

			if standingOnArena1Player2 ~= nil then
				if standingOnArena1Player2.PlayerGui.ScreenGui.Enabled == true then
					standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = false
				end
			end
		end	
	end
end)

-----------------------------------------------------

--				PART2 Events				 --

-----------------------------------------------------

part2.Touched:Connect(function(TouchedPart) -- Touched

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player2 == nil then -- Check if not standing and if not occupied

			part2.BrickColor = BrickColor.new("Teal") -- Set color
			standingOnArena1Player2 = Player
		end	
	end
end)

part2.TouchEnded:Connect(function(TouchedPart)

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player2 ~= nil then -- Check if standing and is occupied
			if   standingOnArena1Player2.PlayerGui.ScreenGui.Enabled == true then
				standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = false
			end
			part2.BrickColor = BrickColor.new("Smoky grey") -- Set color
			standingOnArena1Player2 = nil

			if standingOnArena1Player1 ~= nil then
				if  standingOnArena1Player1.PlayerGui.ScreenGui.Enabled == true then
					standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = false
				end
			end
		end	
	end
end)

while task.wait(0) do
	if standingOnArena1Player2 ~= nil and standingOnArena1Player1 ~= nil then -- checks if both players are on top
		standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = true
		standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = true

Maybe add some print’s and see how far the script goes, also what errors are appearing in the output?

Just checked, I get no error messages

Add a print after every line of code and let me know at what line it stops printing.

in what direction is the script located?

It gets past ‘local humanoid1 = char1:FindFirstChild(“Humanoid”)’ then stops before the death function

Sorry i’m not really sure what you mean by direction. But the script is in serverscriptservice

Can you please post the script with the prints in, and each print should have a number in, then simply tell me which number it gets to.

It gets up to ‘after humanoid1’

local function startEvent()
	
	print("started")
	
	local plr1CurrentKills = 0
	local plr2CurrentKills = 0
	
	local SwordGiver = game.ServerStorage.Sword
	

	local Sword1 = SwordGiver:Clone()
	local char1 = standingOnArena1Player1.Character
	
	print("First Variables")
	
	if char1 then
		local humanoid1 = char1:FindFirstChild("Humanoid")
		
		print("After Humanoid 1")
		
		humanoid1.Died:Connect(function()
			
			print("Detected Death")
			
			plr2CurrentKills = plr2CurrentKills + 1
			
			print("Added Kills")
			
			if plr1CurrentKills < 5 then
				
				print("Less than 5")
				
				if humanoid1 then
					
					print("Detected humanoid")
					
					humanoid1.RespawnLocation = game.Workspace.Arena1Team1
					print("Set respawn")
					Sword1.Parent = standingOnArena1Player1.Backpack
					print("Gave sword")
					humanoid1:EquipTool(Sword1)
					print("Complete")
				end
			end
		end)		
	end

Has the humanoid died? Add a print after if char1 then

Well it printed ‘after humanoid 1’ which is inside the ‘if char1 then’ it doesnt seem to detect when the humanoid has died thats the problem

I understood it gets to this print, but not including.

Anyways, if humanoid1 is not set correctly then it wont detect when the player has died.

what do i need to set the variable to to detect if the player has died?

ok, i sometimes accidentally put the script in the serverstorage, but that is not the issue here