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

Why wont this GetChildren condition work properly?

	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

✓ Accepted answer

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

1 comment

0

ok thanks

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


3 comments

0

ummm

0

like I cant fix all the indentation errors

0

you've goota work on where to indent, and where to not

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