Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script isnt running when IntValue reaches 0?

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 :)

1 comment

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

1 answer

✓ Accepted answer

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

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.