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

Script isnt running when IntValue reaches 0?

Asked by 7 years ago

I have a script and its supposed to fire when an IntValue = 0.

Its a script inside ServerScriptService and the IntValue is inside ReplicatedStorage.

Heres the code

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02 
03-- Sorts game wins or losses
04local BlueTeamPoints = ReplicatedStorage:WaitForChild("BlueTeamPoints")
05local RedTeamPoints = ReplicatedStorage:WaitForChild("RedTeamPoints")
06 
07if BlueTeamPoints.Value == 0 then
08    print("Blue Team Lost")
09    for _, Player in pairs(game.Players:GetChildren()) do
10        if Player.Team.Name == "Really Blue" then
11            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value + 1
12            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 100
13        elseif Player.Team.Name == "Really Red" then
14            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value + 1
15            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 300
View all 29 lines...

It doesnt run at all even when the IntValue is = 0

Does anyone have any ideas? Thank you for your time :)

0
That if statement runs one time and one time only, if you want it to endlessly check if the Value is not 0 then you need a loop Vulkarin 581 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

Well, you forgot to have a repeat

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02 
03-- Sorts game wins or losses
04local BlueTeamPoints = ReplicatedStorage:WaitForChild("BlueTeamPoints")
05local RedTeamPoints = ReplicatedStorage:WaitForChild("RedTeamPoints")
06 
07local loop = true
08 
09while loop do -- Added a loop
10if BlueTeamPoints.Value == 0 then
11    loop = false -- Changes the loop to false which would stop the loop. Same with other
12    print("Blue Team Lost")
13    for _, Player in pairs(game.Players:GetChildren()) do
14        if Player.Team.Name == "Really Blue" then
15            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value + 1
View all 35 lines...
0
I forgot to mention the reason why it didn't work was because, you had it checked the second the script was ran. It just a run once and done. GetGlobals 343 — 7y
Ad

Answer this question