IntValue Not Changing

Hm, could you try this and see what you get?

wait(10)
print("Test")
while true do
    script.Proto.Value = 0
    wait(.29)
    for _, player in pairs(game.Players:GetChildren()) do
        if player.Character.HumanoidRootPart.Position.Y < 80 then
            script.Proto.Value += 1
            print("Proto Value: "..script.Proto.Value)
        end
    end
    script.Final.Value = script.Proto.Value
    print("Amount of players on field: "..script.Final.Value)
end
1 Like

So that actually made it continue printing, but for the Invasion, Juggernaut, and Classic gamemodes the EndRound script fires even when the value is not 0. But somehow your idea fixed a lot. Thanks!

Strange, sometimes scripting can have the most strange effects :thinking: Glad I was able to help a bit though!

Would you have any idea why the EndRound if loop is running even when then IntValue is not at 0? Either way, thanks.

My guess is that you can’t define these variables like these:

image

Instead you’d need to do

while wait(.2) do
    local stats = game.ServerScriptService.StatusBar
    local plrs = game.ServerScriptService["Other Scripts"].PlrCheck.Final
    
    if plrs.Value == 0 then
        --Do the rest of the code line
    end
end

But I have it in a while loop, so the thing would update, right?

It actually took me today to learn this, you can refer to this post:

1 Like

I understand what you’re saying but since the variables are in the while loop they would update every time the loop runs, no?

I can try it but I doubt it would work.

I don’t know, maybe it could also be cause of the loop or something?

Yes, but I have a second value called final that only sets to the value of proto after it completes the loop, and the EndRound scripts detects the final value.

I suggest you to use

CharacterAdded:Wait() instead of adding a 10 second wait wait(10)

Try this code inside the while loop

local Proto = script.Proto
local Final = script.Final
for _, player in pairs(game.Players:GetPlayers()) do
      if player.Character.HumanoidRootPart.Position.Y < 80 then
            Proto.Value += 1
      end
end
Final.Value = Proto.Value
print("Amount of players on field: "..Final.Value)

Be sure to let me know if it works.

Ok. So look at the pics of the explorer again, because Final is a second value that gets set to Proto’s value at the end of the loop. Also I don’t think it would take 10 seconds for a character to load in and also it would error if the character did not exist.

I did the same. Final value is being changed to the value of Proto. Sure it won’t take 10 seconds for the character to load but what about those with bad internet?

Oh sorry by mistake I had written

local Final = script.Proto

I have edited it. Did it work now?

No. Sadly that did not work. I have no idea why EndRound’s if loop is running automatically.

Which intValue isn’t working…?

So in the script EndRound, I check for when the Final value is 0, but the script is running the loop even when it’s not 0.

On your EndRound script

if plrs == 0 then
wait(2)

You need to define the plrs again so like this

if plrs == 0 then
wait(2)
local plrs= game.ServerScriptService["Other Scripts"].PlrCheck.Final.Value
if plrs == 0 then
--Script goes here

I will try that. Thanks for the help.

So I found out that this bug only happens the first time one of a certain 3 gamemodes occur, so I made it so that if it detects 0, it teleports everyone to the lobby so no one gets a win, because no one should techincally be on the field anyways. Thanks for all the help! A special thanks to @JackscarIitt

1 Like