How do I assign a player to a variable (or something like that)

Oops. I noticed an error. I accidentally put plr1CurrentKills or plr2CurrentKills > 5 in the disconnectConnections function. What this does is it will check if plr1CurrentKills is not false or nil, which it isn’t. Otherwise, it will check if plr2’s current kills is greater than 5. What I meant to put was if kills > 5 then.

1 Like

Sorry no, that was me I changed it because I got confused, however I have changed the script back and it’s still not working properly

Here it is:

local connections = {}

			local function disconnectConnections(kills)
				if kills > 5 then
					for i, v in ipairs(connections) do
						v:Disconnect()
					end

					plr1CurrentKills = 0
					plr2CurrentKills = 0
					part1.Transparency = 0
					part1.CanCollide = true
					part2.Transparency = 0
					part2.CanCollide = true
				end
			end

			connections[1] = char1.Humanoid.Died:Connect(function(tag)

				local player1 = game.Players:GetPlayerFromCharacter(char1)
				wait(2)
				player1:LoadCharacter()
				char1 = player1.Character
				local humanoid1 = char1.Humanoid

				plr2CurrentKills = plr2CurrentKills + 1

				disconnectConnections(plr2CurrentKills) -- will check the kills and disconnect connections if it's over 5

				char2.Humanoid.Health = 100

				Sword1.Parent = player1.Backpack
				humanoid1:EquipTool(Sword1)

				char2.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player2Spawn.Position
				)
				char1.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player1Spawn.Position
				)
			end)
			connections[2] = char2.Humanoid.Died:Connect(function(tag)

				local player2 = game.Players:GetPlayerFromCharacter(char2)
				wait(2)
				player2:LoadCharacter()
				char2 = player2.Character
				local humanoid2 = char2.Humanoid


				plr1CurrentKills = plr1CurrentKills + 1

				disconnectConnections(plr1CurrentKills) -- will check the kills and disconnect connections if it's over 5

				char1.Humanoid.Health = 100

				Sword2.Parent = player2.Backpack
				humanoid2:EquipTool(Sword2)

				char1.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player1Spawn.Position
				)
				char2.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player2Spawn.Position
				)
			end)

I think I know what the issue is. The connection is for the character dying, but the character gets destroyed every time they die, and a new one is made whenever they respawn. Maybe try player.CharacterRemoving instead.

1 Like

Sorry where would I put this in the script?

replace char1.Humanoid.Died:Connect(function… with player1.CharacterRemoving:Connect(function…, and the same for the other player.

1 Like

Thank you very much, the teleportation works great. There are a couple issues tho, the player respawns outside the arena and then about one second later are teleported, is there a way to make it more instant, so as soon as they respawn they are teleported, so that they cant really see themselves being spawned. Also, the round never ended, even when I reached 5 kills, both players kept getting teleported.

EDIT: Also is it possible to make the player spawn without a force field?

change the if statement to if kills == 5 or if kills >= 5 if you want it to end on 5 kills. right now it ends on 6 because it checks for if it’s greater than 5.

1 Like

You can change the spawn location’s forcefield time to 0 to spawn without one, however I’d be concerned about spawn killing if you disable it.

2 Likes

Ah yes sorry it works great!

dsmfkjosdnfoksd

Great thanks, the players teleport to opposite sides of an arena so they can’t spawn kill eachother, also I might implement a countdown system, after each kill so the players cant move for a short period of time after one of them dies

Thank you so much for helping me I really appreciate it!

1 Like