#im pretty confused at this bug.

1 messages · Page 1 of 1 (latest)

misty vine
#

Alright so in this code when players are teleporting to the map, the teleport loop sometimes fails which is kinda strange since I waited for the character. Repeated task.wait until map is physically in the workspace. The teleport loop may teleport one player but not the other. Id highly appreciate if someone would help me out

#


local function startRound()
    local activePlayersList = {}
    local activePlayersData = {}
    local deathConnections = {}
    local touchConnections = {}
    local chosenMap

    while #Players:GetPlayers() < playerLimit do
        statusUpdate:FireAllClients("Minimum two players required to play!")
        task.wait(1)
    end

    for i = intermissionTime, 0, -1 do
        statusUpdate:FireAllClients("Intermission: " .. i .. " seconds left!")
        task.wait(1)
    end

    statusUpdate:FireAllClients("Game Starting!")
    task.wait(2)
    statusUpdate:FireAllClients("")

    if #mapQueue == 0 then
        shuffle()
    end

    chosenMap = mapQueue[1]:Clone()
    chosenMap.Parent = workspace
    table.remove(mapQueue, 1)
    local spawnPart = chosenMap:WaitForChild("SpawnLocation")
    repeat task.wait() until chosenMap:IsDescendantOf(workspace)

    roundInProgress = true

    if chosenMap then
        local spawnPosition = spawnPart.Position
        for _, player in Players:GetPlayers() do
            table.insert(activePlayersList, player)
            print("Inserted into the table: " .. player.Name)

            task.spawn(function()
                local character = player.Character or player.CharacterAdded:Wait()
                character:WaitForChild("HumanoidRootPart")
                local randomOffset = Vector3.new(math.random(-5, 5), 3, math.random(-5, 5))
                character:PivotTo(CFrame.new(spawnPosition + randomOffset))
                print("Successfully teleported " .. player.Name)
            end)
        end
    end


#

Another issue is sometimes the players might fall down the map because of slower connection since the map hasnt loaded on their client. How can I make sure a player only teleports when the map loads on their client?

misty vine
#

@vocal phoenix do u mind helping ?

nova pier
#

you can do this by looping through all players and confirming atleast the minimum amount of players have a loaded character

#

by "loaded character" i mean an occupied

.Character```
attribute on the player object.
misty vine
nova pier
# misty vine Something like if player.character then..?

yes.

    local playersWithCharacters = 0
    while playersWithChararcters < playerLimit do
        playersWithCharacters = 0
        for i,v in pairs(game.Players:GetChildren()) do
            if v:IsA("Player") then
                if player.Character then
                   playersWithCharacters +=1
                end
            do
        end
        statusUpdate:FireAllClients("Minimum two players required to play!")
        task.wait(1)
    end

something like this should work. @misty vine

nova pier
misty vine
#

alr

misty vine
nova pier
#

please be sure to correct my mistake in your script.

misty vine
#

no worries!

#

I will also print the value of playersWithCharacters, just incase it was another bug

late valleyBOT
#

studio** You are now Level 5! **studio

misty vine
nova pier
misty vine
nova pier
misty vine
nova pier
# misty vine Not sure if that should be ideal. I mean yeah, sure we are making sure the mini...

the teleportation issue occurs due to the players character // game not being fully loaded, you can either create remote event listener that confirms if the clients game loaded property is true or you can simply confirm if the physical character is loaded.

if the teleportation errors persist then perhaps add a 3 second teleport delay after the clone becomes a descendant of workspace?

misty vine
nova pier
misty vine
#

oh

nova pier
#

if you teleport right when a map spawns it MAY not load fully on all clients.

misty vine
nova pier
#

(clientside teleports are still visible on the server)

#

(just like editing the walkspeed clientside)

misty vine
#

oh

#
    local spawnPart = chosenMap:WaitForChild("SpawnLocation")
    repeat task.wait() until chosenMap:IsDescendantOf(workspace)
task.wait(3)
    roundInProgress = true

    if chosenMap then
        local spawnPosition = spawnPart.Position
        for _, player in Players:GetPlayers() do
            table.insert(activePlayersList, player)
            print("Inserted into the table: " .. player.Name)

            task.spawn(function()
                local character = player.Character or player.CharacterAdded:Wait()
                if character then
                repeat task.wait() until character:FindFirstChild("HumanoidRootPart")
                local randomOffset = Vector3.new(math.random(-5, 5), 3, math.random(-5, 5))
                character:PivotTo(CFrame.new(spawnPosition + randomOffset))
                print("Successfully teleported " .. player.Name)
                end
            end)
        end
    end
#

@nova pier do u think this would work?

#

added several checks

#

repeat task.wait().... is just incase if anything fails since player tp'd from hrp

misty vine