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

Minigame TP Function won't TP all players with their NotReady values being false?

Asked by 5 years ago

In the game I am creating the script has multiple functions to create one streamlined function, one of which handles teleporting players to the starting zone of the map. However, it is suppose to grab only those whose notready.Value = false which is located inside of a folder in the player but when two people have it set to that it only grabs the first one to join the game leaving the other left behind. Then when the game is over and the player who got into the map their notready.Value is reset to true; however, the player left behind stays false but the game won't register them as a player that is ready. It is not a local script and the NotReady value is inside a folder created inside of all players.

Here is the code with the variables to go with it:

local Players = game:GetService("Players")
local AllPlayers = Players:GetChildren()

function TeleportPlayerToMap()
 for i = 1,#AllPlayers do
        if AllPlayers[i]:WaitForChild("Settings").NotReady.Value ~= true then
            if AllPlayers[i] ~= nil then
                if AllPlayers[i].Character ~= nil then
                    if AllPlayers[i].Character:FindFirstChild("Humanoid").Health ~= 0 then
                        local spawns = CurrentMap:FindFirstChild(MapSelected.Value):FindFirstChild("Spawns"):GetChildren()
                        if spawns ~= nil then
                            local ransp = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,3,0)
                            AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
                            wait()
                            if AllPlayers[i] ~= nil then
                                if AllPlayers[i].Character ~= nil then
                                    AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
                                end
                            end
                            wait()
                            if AllPlayers[i] ~= nil then
                                if AllPlayers[i].Character ~= nil then
                                    AllPlayers[i].Character.HumanoidRootPart.CFrame = ransp
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end
0
You don’t need all of those if statements...holy! User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I don’t think you need all of those if statements...here’s your code...

local players = game:GetService("Players"):GetPlayers()

function teleportPlayers()
    for _, v in pairs(players) do
        if v.Character and not v.Settings.NotReady.Value then
            v.Character.HumanoidRootPart.CFrame = -- CFrame coding here
        end
    end
end
0
Thank you; however the issue still remains. It will only grab the first player to connect to the server with a changed NotReady value despite player2 having his value being false as well. I don't know why this is happening and I am still learning. rikublue 0 — 5y
Ad

Answer this question