Player gets teleported the first time but not the second time! Help?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to learn how to fix this type of issue.
  2. What is the issue? Include screenshots / videos if possible!
    The issue is that the player gets teleported the first time but not when the murderer or sheriff dies or all of the innocents die, it only works if the time has run out.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Well, i did look on the internet, but i didnt find anything like this.

Code:

MainHandler:

local BadgeService = game:GetService("BadgeService")
local GS = require(game.ServerStorage.MS.GameSettings)

local roundLength = GS.roundTime
local intermissionLength = GS.intermissionTime
local status = game.ReplicatedStorage.IntermissionStatus
local inround = game.ReplicatedStorage.InRound

local roundStart = game.ReplicatedStorage.remoteEvents.round.roundStart
local roundEnd = game.ReplicatedStorage.remoteEvents.round.roundEnd

local showRole = game.ReplicatedStorage.remoteEvents.displayRole:WaitForChild("displayR")
local hideRole = game.ReplicatedStorage.remoteEvents.displayRole:WaitForChild("hideR")

local lobby = game.ReplicatedStorage.remoteEvents.maps.lobby

local Events = game.ReplicatedStorage.remoteEvents
local sl = Events.mapLoading.StartLoad
local el = Events.mapLoading.EndLoad

local endround = game.ReplicatedStorage.remoteEvents.round.endRound.EndRound

game.Players.PlayerAdded:Connect(function(plr)
	player = plr
end)

endround.OnServerEvent:Connect(function(player)
	script.Disabled = true
	inround.Value = false
	roundEnd:FireAllClients()
	hideRole:FireAllClients()
	status.Value = "GAME OVER!"
	wait(5)
	script.Disabled = false
end)

local function roundTimer()
	while wait() do
		for i = intermissionLength, 1, -1 do
			inround.Value = false
			wait(1)
			status.Value = "Intermission: ".. i .." seconds left!"
			wait(1)
			roundEnd:FireAllClients()
		end
		for i = roundLength, 1, -1 do
			inround.Value = true
			wait(1)
			status.Value = "Game: ".. i .." seconds left!"
			wait(1)
			roundStart:FireAllClients()
		end	
	end
end

inround.Changed:Connect(function()
	if inround.Value == true then
		for i,v in pairs(game.Players:GetChildren()) do
			if player then
				player.TeamColor = BrickColor.new("Institutional white")
				BadgeService:AwardBadge(player.UserId, 2124669092)
			else
				return
			end
		end	
		sl:FireAllClients()
		wait(GS.transitionTime)
		el:FireAllClients()
		showRole:FireAllClients()
		wait(5)
		hideRole:FireAllClients()
	else
		lobby:FireAllClients()
		for i,v in pairs(game.Players:GetChildren()) do
			if player then
				player.TeamColor = BrickColor.new("Medium stone grey")
			else
				return
			end
		end	
	end
end)

if not script.Disabled == true then
	spawn(roundTimer)
end

LoadingMapHandler:

local Events = game.ReplicatedStorage.remoteEvents
local sl = Events.mapLoading.StartLoad
local el = Events.mapLoading.EndLoad

local GS = game.ServerStorage.MS.GameSettings

local btpS = game.Workspace.BattleBusTP

sl.onServerEvent:Connect(function(player)
	local char = player.Character

	char.HumanoidRootPart.CFrame = btpS.CFrame
end)

el.onServerEvent:Connect(function(player)
	local milbaseR = game.ReplicatedStorage.remoteEvents.maps.milbase
	milbaseR:FireAllClients()
end)

MapHandler:

local milbaseS = game.Workspace.MilbaseSpawn
local lobbyS = game.Workspace.LobbySpawn
local ravenRockS = game.Workspace.ravenrockSpawn
local spS = game.Workspace.shoppingPlazaSpawn

local mineshaftMN = game.ServerStorage.mineshaft
local ravenRockMN = game.ServerStorage.ravenRock
local milBaseMN = game.ServerStorage.MilBase
local spMN = game.ServerStorage.shoppingPlaza
local votedMap = game.ReplicatedStorage.votedMap

local milbaseR = game.ReplicatedStorage.remoteEvents.maps.milbase
local ravenRockR = game.ReplicatedStorage.remoteEvents.maps.ravenRock
local lobby = game.ReplicatedStorage.remoteEvents.maps.lobby
local spR = game.ReplicatedStorage.remoteEvents.maps.spMC
local GS = require(game.ServerStorage.MS.GameSettings)


milbaseR.OnServerEvent:Connect(function(player)
	if votedMap.Value == "MilBase" then
		local char = player.Character
		
		wait(1)
		milBaseMC = milBaseMN:Clone()
		milBaseMC.Parent = game.Workspace
		wait(GS.teleportTime)
		char.HumanoidRootPart.CFrame = milbaseS.CFrame
	elseif votedMap.Value == "ShoppingPlaza" then
		local char = player.Character
		
		spMC = spMN:Clone()
		spMC.Parent = game.Workspace
		wait(GS.teleportTime)
		char.HumanoidRootPart.CFrame = spS.CFrame
	elseif votedMap.Value == "RavenRock" then
		local char = player.Character
		
		ravenRockMC = ravenRockMN:Clone()
		ravenRockMC.Parent = game.Workspace
		wait(GS.teleportTime)
		char.HumanoidRootPart.CFrame = ravenRockS.CFrame
	else
		player:Kick("An error has occured please re-join!")
	end
end)

lobby.OnServerEvent:Connect(function(player)
	local char = player.Character
	wait(GS.teleportTime)
	char.HumanoidRootPart.CFrame = lobbyS.CFrame

	if ravenRockMC then
		ravenRockMC:Destroy()
	elseif milBaseMC then
		milBaseMC:Destroy()
	elseif spMC then
		spMC:Destroy()
	end
end)

Someone please help!

Hi there, so if you wanted to teleport people, I would probably keep it in the server script and use iteration to teleport everybody.

local players = game:GetService(“Players”)
for i, v in pairs(game.Players:GetChildren()) do
if v.TeamColor == Brickcolor.new(“Lime Green”) then --Whatever participants are
v.TeamColor == Brickcolor.new(“Blue”) – Whatever spectator is
v.Character.HumanoidRootPart.Position = Vector3.new(Location)
end
end

Just an idea… I can’t see where you call the endRound via a local script. But that’s how I’d do it. Best of luck. Let me know if you need me to answer something else.

As i said in the post, the teleport works fine when the timer runs out but when the murderer wins or dies then the timer goes on without teleporting the player.

The script where the endround is located (server script) i have a client to server redirect script btw:

local murdererChosen = game.ReplicatedStorage.remoteEvents.roles.murderer
local sheriffChosen = game.ReplicatedStorage.remoteEvents.roles.sheriff
local innocentChosen = game.ReplicatedStorage.remoteEvents.roles.innocent
local neutral = game.ReplicatedStorage.remoteEvents.roles.neutral
local UaZkOmZtyD = game.ReplicatedStorage.UaZkOmZtyD

local roundStart = game.ReplicatedStorage.remoteEvents.round.roundStart
local roundEnd = game.ReplicatedStorage.remoteEvents.round.roundEnd

local inround = game.ReplicatedStorage.InRound

local player = game.Players.LocalPlayer

local murdererTaken = false
local sheriffTaken = false

local ran1 = false
local ran2 = false
local isInRound = false

local players = game:GetService("Players")

local endround = game.ReplicatedStorage.remoteEvents.round.endRound.EndRound


local function insertTag(plrs, tagName)
	for index, plr in pairs(plrs) do
		if plr:FindFirstChild(tagName) then return end

		local tag = Instance.new("StringValue")
		tag.Name = tagName
		tag.Parent = plr

	end

end
alive = {}
local function giveRoles()
	if not ran2 == true then
		local contestants = {};
		victims = {}


		local murderer;
		local sheriff;

		for index, player in pairs(players:GetPlayers()) do
			if player then
				table.insert(contestants, player)
			end
		end

		murderer = contestants[math.random(#contestants)]

		for index, player in pairs(contestants) do
			if not player then
				table.remove(contestants, index)
			end

			if player == murderer then
				table.remove(contestants, index, player)
				murdererChosen:FireClient(player)
				murdererPlayer = player
				table.insert(alive, player)
				--game.ServerStorage.pp.Murderer = player.Name
				break
			end
		end

		sheriff = contestants[math.random(#contestants)]

		for index, player in pairs(contestants)  do
			if not player then
				table.remove(contestants, index)
			end

			if player == sheriff then
				table.remove(contestants, index, player)
				sheriffChosen:FireClient(player)
				sheriffPlayer = player
				table.insert(alive, player)
				--game.ServerStorage.pp.Sheriff = player.Name
				break
			end
		end

		for index, player in pairs(contestants) do
			if not player then table.remove(contestants, index) end

			if not murderer and not sheriff then
				table.insert(victims, player)
				innocentChosen:FireAllClients()
				table.insert(alive, player)
			end
		end
		contestants = {}

		insertTag(victims, "Victim")

		insertTag({murderer}, "Murderer")

		insertTag({sheriff}, "Sheriff")
		ran2 = true
	end
end

function getPositionOfPlayer(tab,el)
	for i,v in pairs(tab) do
		if v == el then
			return i
		end
	end	
end

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local success, response
			success, response = pcall(function()
				table.remove(alive, getPositionOfPlayer(alive, player))
			end)
			if success then
				print("PLAYER WAS SUCCESSFULLY REMOVED FROM THE TABLE! INFO: N/A")
			else
				print("PLAYER WAS NOT SUCCESSFULLY REMOVED FROM THE TABLE! INFO: ".. response)
			end
		end)
	end)
end) 

roundStart.OnServerEvent:Connect(function(plr)
	isInRound = true
	if ran1 == true then
		
	else
		ran1 = true
		giveRoles()
	end
	
	local murderer = murdererPlayer
	local sheriff = sheriffPlayer
	if table.find(alive, sheriff) and not table.find(alive, murderer) then
		endround:FireAllClients()
	elseif not table.find(alive, murderer) and not table.find(alive, sheriff) then
		endround:FireAllClients()
	elseif not table.find(alive, sheriff) and table.find(alive, murderer) then
		if #victims > 1 or #victims == 1 then
			local newSherif = victims[math.random(#victims)]
			sheriffChosen:FireClient(newSherif)
		end
	elseif #victims == 0 or #victims <= 0 then
		endround:FireAllClients()
	else
		--everyone is alive
	end
	wait(2)
end)

roundEnd.OnServerEvent:Connect(function(plr)
	isInRound = false
	murdererTaken = false
	sheriffTaken = false
	ran1 = false
	ran2 = false
end)

local KzOnzKAp = game.ReplicatedStorage.KzOnzKAp
local shouldISwitch = false

KzOnzKAp.OnServerEvent:Connect(function(player)
	shouldISwitch = true
end)

UaZkOmZtyD.OnServerEvent:Connect(function(player)
	if shouldISwitch == true then
		print("Thanks for the purchase! Roles have been switched!")
		giveRoles()
		shouldISwitch = false
	else
		player:Kick("Do not cheat! You got kicked for trying to switch roles, but didnt actually buy them.")
	end
end)

It seems that it just doesnt work when the script gets disabled then re-enabled

Oh i fixed it, i just changed the position of:

sl:FireAllClients()
wait(GS.transitionTime)
el:FireAllClients()
showRole:FireAllClients()
wait(5)
hideRole:FireAllClients()

to the top