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

Why wont this GetChildren condition work properly?

Asked by 4 years ago
    until roundLength == 0 or canWin == false or #workspace.InGame:GetChildren() == 0

        for i = 1, #players do
        if players[i].Character ~= nil then
            players[i].Character.Parent = workspace


    wait(10)
    map:Destroy()
if
     workspace.InGame:GetChildren() == 0
    then

    local Part = game.Workspace.MainSpawn
    local Stops = game.Workspace.Sounds.InLevel:GetChildren()

for _, v in pairs (EndParts) do
Part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
            game.Lighting.ClockTime = 14
        for _, music in pairs (Stops)
        do
            music:Stop()
        end
        humanoid.WalkSpeed = 16
        v.Transparency = 0
        v.CanCollide = true
                    end
                end)
            end
        end 
        end
    end
end

basically, when you're in a round in the game you get put into an InGame folder in workspace, and when you're out of the round the parent of the character is workspace again, everything I just said works but why won't it execute the script under the if statement? If more of the script is needed I can provide it, however, it's very long.

2 answers

Log in to vote
1
Answered by 4 years ago

Hello.

Solution:

To get the number of items in a table, you must put a hashtag (#) before the table.

Fixed Code:

   until roundLength == 0 or canWin == false or #workspace.InGame:GetChildren() == 0

        for i = 1, #players do
        if players[i].Character ~= nil then
            players[i].Character.Parent = workspace


    wait(10)
    map:Destroy()
if
     #workspace.InGame:GetChildren() == 0
    then

    local Part = game.Workspace.MainSpawn
    local Stops = game.Workspace.Sounds.InLevel:GetChildren()

for _, v in pairs (EndParts) do
Part.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
            game.Lighting.ClockTime = 14
        for _, music in pairs (Stops)
        do
            music:Stop()
        end
        humanoid.WalkSpeed = 16
        v.Transparency = 0
        v.CanCollide = true
                    end
                end)
            end
        end 
        end
    end
end

0
ok thanks PastorCL3Z 75 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Im pretty sure you need to put the condition next to the if statement like this ~~~~~~~~~~~~~~~~~ if workspace.InGame:GetChildren() == 0then

local Part = game.Workspace.MainSpawn
local Stops = game.Workspace.Sounds.InLevel:GetChildren()

for _, v in pairs (EndParts) do
    Part.Touched:Connect(function(hit)
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
     if humanoid then
             game.Lighting.ClockTime = 14
         for _, music in pairs (Stops) do
        music:Stop()
         end
        humanoid.WalkSpeed = 16
        v.Transparency = 0
        v.CanCollide = true
                end
            end)
        end
    end 
    end
end

end

~~~~~~~~~~~~~~~~~

0
ummm ayuu_ondev 60 — 4y
0
like I cant fix all the indentation errors ayuu_ondev 60 — 4y
0
you've goota work on where to indent, and where to not ayuu_ondev 60 — 4y

Answer this question