IntValue Not Changing

So I’m making a script that detects how many players are below Y 80 and if it is 0 then it ends the round. A pic of my explorer:

image
PlrCheck is in a folder in ServerScriptService.

Here’s the PlrCheck script

Here’s the EndRound script

This works fine in Studio but when I go into the game…
So basically the IntValue stays at 0 no matter what and the PlrCheck script just stops printing after a bit.

Hopefully you can help! Thanks for your time.

Could it possibly be because of the player not entirely loading in right? That’s maybe the only thing I can really think of, your EndRound script looks fine though :thinking:

The player is loading in correctly for sure. I ihave a wait(10) in the beginning so that gives enough time to load in.

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.