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

How do I fix this?

Asked by 9 years ago
01function onPlayerEntered(newPlayer)
02    local stat = Instance.new("BoolValue",newPlayer)
03    stat.Name = "Playing"
04    stat.Value = false
05end
06 
07game.Players.ChildAdded:connect(onPlayerEntered)
08while true do
09        for _,v in pairs (game.Players:GetPlayers()) do
10            for _,v in pairs (v:GetChildren()) do
11                if v.Name == "Playing" then
12                    if v.Value == true then
13                        script.Parent.Value = script.Parent.Value + 1
14                    end
15 
16                end
17            end
18        end
19wait()
20end

How do I make it so it doesn't keep adding onto the numbervalue? I know this has to do with the while true do, but is there a certain loop that i can use that doesn't repeat previous ones?

1 answer

Log in to vote
3
Answered by 9 years ago

I see by your coding style, you are setting up your game to fail in the long run. As an example, I am going to provide you some code which: 1) Could improve your coding style. 2) Create a more secure game.

01local PlayerManager={} do
02    PlayerManager.RegisteredPlayers={};
03    local Methods={};
04    local Metatable={__index=Methods};
05 
06    function Methods:Destroy()
07        PlayerManager.RegisteredPlayers[self.UserId]=nil;
08    end;
09    function Methods:IsPlaying()
10        return self.Data.IsPlaying;
11    end;
12    function Methods:ToggleIsPlaying()
13        self.Data.IsPlaying=not self.Data.IsPlaying;
14        return self:IsPlaying();
15    end;
View all 47 lines...

If you have any questions or concerns on what my code does, feel free to

0
Ladies and Gentlemen we have an OOPer Validark 1580 — 9y
0
that we do, that we do... pluginfactory 463 — 9y
Ad

Answer this question