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

Trying add a repeated check of a variable. Could someone help?

So I'm trying to add a check that always sees whether _G.score is more than a certain integer. This is what I've put so far:


_G.score = 0

while true do
	if _G.score < 5 then
		 game.ReplicatedStorage.ChangeChar:FireServer(game.ReplicatedStorage.Bacteria)
	end
	
	if _G.score > 5 and _G.score < 15 then
		game.ReplicatedStorage.ChangeChar:FireServer(game.ReplicatedStorage.Virus)
	end
	wait(0.5)
end

However, this causes it to fire the first piece of code repeatedly rather than just check if it's more than 5 and if it is then FireServer.

1 comment

0

You can add a debounce to check if it has already fired or not.

1 answer

✓ Accepted answer

If this is what you're looking for, consider accepting my answer.

local db = false
_G.score = 0

while true do
	if db == false then
		db = true
		 if _G.score < 5 then
            game.ReplicatedStorage.ChangeChar:FireServer(game.ReplicatedStorage.Bacteria)
    	 end

   		if _G.score > 5 and _G.score < 15 then
       	   game.ReplicatedStorage.ChangeChar:FireServer(game.ReplicatedStorage.Virus)
		    	end
		wait(0.5) --//Wait time before db = false
		db = false
	end
end

Lemme know if you get any errors.

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