How to set a players spawn location to a part

Hello everyone, I’m trying to make it so that while a player has less than 5 kills, then they keep respawning on a part called ‘arena1team1’ but i’m not sure how to do this…
Here is the part of script where im trying to implement it, as you can see I tried to do it but it just gave me error messages and didnt work.

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

	local Sword1 = SwordGiver:Clone()
	local char1 = standingOnArena1Player1.Character
	
	print("Variables working fine")
	
	
	if char1 then
		
		print("Detected that i'm char1")
		
		local humanoid1 = char1:FindFirstChild("Humanoid")

		if humanoid1 then
			
			print("Approved that i'm humanoid")

			while plr1CurrentKills < 5 do
				print("Detected less than 5 kills")
				char1.Humanoid.Died:Connect(function(tag)
					print("Detected Death")
					plr2CurrentKills = plr2CurrentKills + 1
					print("Changed kills value")
					standingOnArena1Player1.RespawnLocation = game.Workspace.Arena1Player1
					print("Set new location")
				end)
				Sword1.Parent = standingOnArena1Player1.Backpack
				humanoid1:EquipTool(Sword1)
				print("Gave sword")
				wait(1)
			end		
			standingOnArena1Player1.RespawnLocation = game.Workspace.SpawnLocation
			print("Reset the spawn location")
		end
	end		

	local Sword2 = SwordGiver:Clone()
	local char2 = standingOnArena1Player2.Character
	if char2 then

		print("Detected that i'm char1")

		local humanoid2 = char2:FindFirstChild("Humanoid")

		if humanoid2 then

			print("Approved that i'm humanoid")

			while plr2CurrentKills < 5 do
				print("Detected less than 5 kills")
				char2.Humanoid.Died:Connect(function(tag)
					print("Detected Death")
					plr1CurrentKills = plr1CurrentKills + 1
					print("Changed kills value")
					standingOnArena1Player2.RespawnLocation = game.Workspace.Arena1Player2
					print("Set new location")
				end)
				Sword2.Parent = standingOnArena1Player2.Backpack
				humanoid2:EquipTool(Sword2)
				print("Gave sword")
				wait(1)
			end		
			standingOnArena1Player2.RespawnLocation = game.Workspace.SpawnLocation
			print("Reset the spawn location")
		end
	end
end

Note: Everything works fine except the spawn location, so its not that the game isn’t detecting the death or anything, its purely the way I have tried to set the spawn location is wrong.

You could teleport them when they spawn. Use the Player.CharacterAdded event to detect when they spawn, and then set their HumanoidRootPart’s position to where you want it to be.

Or make teams and different SpawnPoints for each. Then just move the player to a team according to their kill count.

2 Likes

Thanks for the response, Would they be able to see themselves being teleported or would it be so quick they wouldnt really notice?

They wouldn’t notice, as both the event and the teleport are on the server. Maybe a single frame would be visible if the server is laggy.

3 Likes

Why not just use a SpawnLocation?

because i dont want people spawning into the arena when they join the game

Set their RespawnLocation to the spawn you want them at when they join the game.

2 Likes

A loading screen would cover that.