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

How do i make auto point system when status = "YES"?

Im trying to make it so when text changes to no, auto ticks(points) is off but when text changes to yes, it will turn on again

I made a system and it works but when i turn it off and on again it does not give it anymore, even if text says yes

amount = 1
timedelay = 1
currencyname = "Ticks"
local status = workspace.AutoTicks.Status.SurfaceGui.TextButton

while status.Text == "YES" do
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end

2 answers

✓ Accepted answer

I suggest you don't use a while loop to check if a property changed, instead use .Changed, which way better for performance. It will fire when a property has changed, connect it with status, and each time it fires it might be possible that the Text changed to "YES", if so add to the saved value.

This does not work with a while loop, because it only checks once. Meaning if you started the game, the text was "YES", but then it was changed to something else, then brought back to "YES", it wouldn't find out that it changed back to "YES" again, because it already checked the first time, it was "YES", and as soon as changed it stopped looping and carried on with the script to no longer check again.

status.Changed:Connect(function()
	if status.Text == "YES" then
		v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
	end
end

1 comment

0

thanks

The problem that I see is that the while statement only runs once, so once it is finished that's the end of the script and it stops, to prevent this you would put it in a loop to check the text every second or so, here's the script I would use:

amount = 1
timedelay = 1
currencyname = "Ticks"
local status = workspace.AutoTicks.Status.SurfaceGui.TextButton

while true do
	while status.Text == "YES" do
	    wait(timedelay)
	    for i,v in pairs(game.Players:GetPlayers()) do
	        if v:FindFirstChild("leaderstats") then
	            v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
	        end
	    end
	end
	wait(1)
end

1 comment

0

This will work indeed, but it's very not efficient, a while loop inside of a while loop is bad practice, always try to avoid it.

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