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

Boolean value not being added to all players (in pairs loop)?

I am currently trying to make a round game, where every round the players in the game get teleported in and out, to determine who is still alive in the round, I give everyone a boolean value that gets removed when they die. However, the in pairs loop doesn't give everyone the boolean value.

Here's my script:

while true do
	
	Status.Value = "Waiting for enough players"
	
	repeat wait(1) until game.Players.NumPlayers >= 1
	
	
	for i  = 10, 1, -1 do
		Status.Value = "Intermission "..i.." seconds left!"
		wait(1)
	end
		
	local plrs = {}
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs, player)
		end
	end
	
	print(unpack(plrs))
	
	wait()
	
	Status.Value = "Teleporting..."
	
	for i, player in pairs(plrs) do
		if player then
			
			character = player.Character
			print("test") 
			
			if character then
				--Teleport 
				
				local gamepad = game.Workspace.GameParts.GamePad
				
				character:FindFirstChild("HumanoidRootPart").CFrame = gamepad.CFrame
				
				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character
				
			else 
				--There is no character
				if not player then
					table.remove(plrs, i)
				end
			end
		end

Any ideas on why this script doesn't give all players the "GameTag" BoolValue?

1 answer

I had to delete the answer to post this but i fixed a bunch of problems hopefully it works.

while true do

    Status.Value = "Waiting for enough players"

    repeat wait(1) until game.Players.NumPlayers >= 1


    for i  = 10, 1, -1 do
        Status.Value = "Intermission "..i.." seconds left!"
        wait(1)
    end

    local plrs = game.Players:GetPlayers()

    print(unpack(plrs))

    wait()

    Status.Value = "Teleporting..."

    for player = 1, #plrs do
        if plrs[player] then

            character = plrs[player].Character
            print("test") 

            if character then
                --Teleport 

                local gamepad = game.Workspace.GameParts.GamePad

                character:WaitForChild("HumanoidRootPart", 5).CFrame = gamepad.CFrame

                local GameTag = Instance.new("BoolValue")
                GameTag.Name = "GameTag"
                GameTag.Parent = character
                end
            end
        end

2 comments

0

You accidentally wrote GetPlayer instead of GetPlayers

0

ah i'll edit it

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