Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago
Edited 8 years ago

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

0
Tbh, everything looks correct. FiredDusk 1466 — 8y
0
ikr idk why it doest work TheTopBoss -2 — 8y
0
On line 24 you have a loop whitch will never end User#5423 17 — 8y
0
I broke that loop if the players in the game are more than 2 TheTopBoss -2 — 8y
View all comments (4 more)
0
Your check to break the loop is not actually located inside the loop you're trying to break. 2eggnog 981 — 8y
0
from like 24 - 35 there is no break so the loop will not stop User#5423 17 — 8y
0
How Can I fix this, I tried but didnt work TheTopBoss -2 — 8y
0
Nvm thanks for the help guys I worked on it for hours and figured it out TheTopBoss -2 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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.

Ad

Answer this question