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

Why is this script always telling me that there aer 0 people in the team?

I have a script here:


Counter = Instance.new("IntValue", workspace)
Counter.Name = "PlayerCount"
Counter.Value = #game.Teams.Eliminating:GetPlayers()
print(Counter.Value)

game.Workspace.PlayerCount.Changed:connect(function()
	if Counter.Value < 1 or Counter.Value == 1 then
		game.Workspace.Ground:Destroy()
		print("Ground has melted")
		game.Lighting.Ground:Clone().Parent = game.Workspace
		print("Snow has refrosen")
		wait(3)
		for _, player in ipairs(game.Players:GetPlayers()) do
    player.Team = game.Teams.Eliminating
		print("Teams have changed")
		end
	end
end)

The problem is that, when I print the counter value, it always gives me 0, even if I am in the team, can someone explain why, and possibly give me a fix?

1 comment

0

Because you're relying on a constant variable. The value never changes from when the game first loads up. To fix this, move line 3 inside the .Changed event function.

1 answer

Here's a little fix.

Counter = Instance.new("IntValue", workspace)
Counter.Name = "PlayerCount"
-- Removing line 3
print(Counter.Value)

game.Workspace.PlayerCount.Changed:connect(function()
    if Counter.Value < 1 or Counter.Value == 1 then
        Counter.Value = #game.Teams.Eliminating:GetPlayers() -- Moving line 3 to .Changed function
        game.Workspace.Ground:Destroy()
        print("Ground has melted")
        game.Lighting.Ground:Clone().Parent = game.Workspace
        print("Snow has refrosen")
        wait(3)
        for _, player in ipairs(game.Players:GetPlayers()) do
    player.Team = game.Teams.Eliminating
        print("Teams have changed")
        end
    end
end)

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