Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Players wont teleport to the location and no errors show up in the output?

The code works fine until the maps gets clone into workspace, Im trying to pick a killer and teleport him to a part and the others will go to another spawn or part this is what I have so far

--By TheTopBoss

local serverStorage = game:GetService("ServerStorage")
local maps = serverStorage.Maps:GetChildren()

h = Instance.new("Hint", game.Workspace)

while true do

	if game.Players.NumPlayers >= 2 then
		--Choosing Map
		h.Text = "Game Will Start"
		ranMap = math.random(1, #maps)
		mapChosen = maps[ranMap]
		h.Text = "Map Chosen : ".. mapChosen.Name
		wait(3)
		mapChosenClone = mapChosen:Clone()
		mapChosenClone.Parent = game.Workspace
		wait(3)
		
		
		
		--Teleporting Players
		while true do
		wait(5)
		contestants = {}
		for _, player in pairs(game.Players:GetPlayers()) do
			if player and player.Character then
				local humanoid = player.Character:WaitForChild("Humanoid")
				if humanoid and humanoid.Health > 0 then 
					table.insert(contestants, player)
				end
			end
		end
	end
		
		if #contestants >= 2 then 
			break
		else
		end
		
	while true do
		wait(1)
		RandomValue = math.random(1, #contestants)
		wait()
		RandomPlayerName = contestants[RandomValue]
		wait()
		h.Text = RandomPlayerName.." has been chosen as the killer!"
		wait(4)
		h.Text = "Teleporting all players to the map..."
		RandomPlayer = game.Players:FindFirstChild(RandomPlayerName)
		if RandomPlayer then
		RandomPlayer.Character.Torso.CFrame = CFrame.new(-1942.5, 311.89, 29.5)
		wait(5)
		for i, v in pairs(game.Players:GetPlayers()) do
		if v.Name ~= RandomPlayer.Name then
		v.Character.Torso.CFrame = CFrame.new(-2173.6, 316.69, 211.6)
		wait()
		end
		end
	end
		end
		
		-- Time Before Game ends
		for i = 10, 1, -1 do
			h.Text = "Time left : " .. i
			wait(1)
		end
		h.Text = "Game has ended"
		wait(3)
		mapChosenClone:Destroy()
		
		--Intermission time
		for i = 30, 1, -1 do
			h.Text = "Intermission : " .. i
			wait(1)
		end
	else h.Text = "More Players are needed"		
end
	
	wait()
	
end

8 comments

0

Tbh, everything looks correct.

0

ikr idk why it doest work

0

On line 24 you have a loop whitch will never end

0

I broke that loop if the players in the game are more than 2

0

Your check to break the loop is not actually located inside the loop you're trying to break.

0

from like 24 - 35 there is no break so the loop will not stop

0

How Can I fix this, I tried but didnt work

0

Nvm thanks for the help guys I worked on it for hours and figured it out

1 answer

I think the issue is here:

 while true do
        wait(1)
        RandomValue = math.random(1, #contestants)
        wait()
        RandomPlayerName = contestants[RandomValue]
        wait()
        h.Text = RandomPlayerName.." has been chosen as the killer!"
        wait(4)
        h.Text = "Teleporting all players to the map..."
        RandomPlayer = game.Players:FindFirstChild(RandomPlayerName)
        if RandomPlayer then
        RandomPlayer.Character.Torso.CFrame = CFrame.new(-1942.5, 311.89, 29.5)
        wait(5)
        for i, v in pairs(game.Players:GetPlayers()) do
        if v.Name ~= RandomPlayer.Name then
        v.Character.Torso.CFrame = CFrame.new(-2173.6, 316.69, 211.6)
        wait()
        end
        end
    end
        end

Since you're doing a loop and you're also picking the killer, you will end up picking more than one. If that isn't the issue, it could become it. Also, try putting:

print"Line 32 has executed"

Or something like that everywhere, especially where you think it'll break. That's a really good trick to find out where the problem is starting and how to fix it.

This discussion is preserved as it was. New answers, comments, and votes are closed.