Rounds system not teleporting players

im making a game where one killer chases survivors kinda like forsaken but when the round starts only the killer is teleported, pls help me.
this is the entire code for it

local playerCount = #game.Players:GetPlayers()
local plrs = game.Players:GetPlayers()

wait(1)

spawn(function()
	while true do
		wait(0)
		playerCount = #game.Players:GetPlayers()
	end
end)

while true do
	wait(1)
	if playerCount <= 1 then
		script.Parent.Time.Value = 60
	else
		script.Parent.Time.Value = script.Parent.Time.Value - 1
		print("a")
		if script.Parent.Time.Value == 0 then
			if workspace.inRound.Value == false then
				workspace.inRound.Value = true
				script.Parent.Time.Value = 240
				local players = game:GetService("Players"):GetPlayers()
				local killer = players[math.random(1, #players)]
				killer.Character.killer.Value = true
				local folder = workspace:FindFirstChild("Killer Spawns"):GetChildren()
				print(folder) -- for testing
				if #folder > 0 then -- just try it
					local Killerspawn = folder[Random.new():NextInteger(1, #folder)]
					killer.Character:WaitForChild("HumanoidRootPart").CFrame = Killerspawn.CFrame * CFrame.new(0, 4, 0)
					print(Killerspawn)
				else
					print("No spawns!")
				end

				print(killer)
				for _, player in pairs(players) do -- this is where it loops through players and chooses survivor spawns are chosen randomly for each player
					if player.Name == killer.Name then return end
					if player.Character and player.Character:FindFirstChild("survivor") then 
						player.Character.survivor.Value = true
					end
					print(player)
					local spawns = workspace:FindFirstChild("Survivor spawns"):GetChildren()
					if #spawns > 0 then
						local survivorspawn = spawns[Random.new():NextInteger(1, #spawns)] -- this is where survivors are teleported to random spawns
						killer.Character:WaitForChild("HumanoidRootPart").CFrame = survivorspawn.CFrame * CFrame.new(0, 4, 0)
						print(survivorspawn)
					else
						print("No spawns!")
					end
				end
			else
				workspace.inRound.Value = false
				script.Parent.Time.Value = 50
			end
		end
	end
end

when i edit it so that it works when theres only one player it works for that player but when theres more than one it only teleports the killer.

1 Like

ok firstly, replace return with continue. return will COMPLETELY exit out of the loop and will skip other players. continue on the other hand simply skips that iteration of the loop

second, i think this is the main problem. you should be teleporting the player, not the killer, so it should be smth like player.Character:WaitForChild("Humanoid... blah blah blah

thank you i didn’t notice that

1 Like

no problem! let me know if it works!

just a side note btw, you should probably make these minor changes:
wait() → task.wait()
spawn() → task.spawn()

3 Likes

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