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

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Sorts game wins or losses
local BlueTeamPoints = ReplicatedStorage:WaitForChild("BlueTeamPoints")
local RedTeamPoints = ReplicatedStorage:WaitForChild("RedTeamPoints")

if BlueTeamPoints.Value == 0 then
    print("Blue Team Lost")
    for _, Player in pairs(game.Players:GetChildren()) do
        if Player.Team.Name == "Really Blue" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 100
        elseif Player.Team.Name == "Really Red" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 300
        end
    end
    elseif RedTeamPoints.Value == 0 then
    print("Red Team Lost")
    for _, Player in pairs(game.Players:GetChildren()) do
        if Player.Team.Name == "Really Red" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 100
        elseif Player.Team.Name == "Really Blue" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 300
        end
    end
end

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Sorts game wins or losses
local BlueTeamPoints = ReplicatedStorage:WaitForChild("BlueTeamPoints")
local RedTeamPoints = ReplicatedStorage:WaitForChild("RedTeamPoints")

local loop = true

while loop do -- Added a loop
if BlueTeamPoints.Value == 0 then
    loop = false -- Changes the loop to false which would stop the loop. Same with other
    print("Blue Team Lost")
    for _, Player in pairs(game.Players:GetChildren()) do
        if Player.Team.Name == "Really Blue" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 100
        elseif Player.Team.Name == "Really Red" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 300
        end
    end
    elseif RedTeamPoints.Value == 0 then
    loop = false
    print("Red Team Lost")
    for _, Player in pairs(game.Players:GetChildren()) do
        if Player.Team.Name == "Really Red" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Losses").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 100
        elseif Player.Team.Name == "Really Blue" then
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Wins").Value + 1
            ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value = ReplicatedStorage.DataFile[Player.Name]:WaitForChild("Crystals").Value + 300
        end
    end
end
end
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