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

Not looping when forever after a certain number?

I am trying to make a cookie clicker game on my surfacegui. When you have 100 cookies or more you can buy a Worker, who makes the cookies with a loop, but the loop i put Mouse Down function does not work. The loop stops when 2 cookies are added but it cant add more than 2 cookies.. Help?

local cookie = script.Parent
local noob = script.Parent.Parent.NoobWorker.Script
local cooki21e = script.Parent.Parent.Parent.Parent.RealAmount.IntValue
local cooke1 = script.Parent.Parent.Parent.Parent.RealAmount
local oneNOOB = script.Parent.Parent.Parent.Parent.Noob1

script.Parent.MouseButton1Down:Connect(function()
if cooki21e.Value < 100 then
	print("Below 100")
elseif cooki21e.Value > 100 then
		cooki21e.Value = cooki21e.Value - 100
			cooke1.Text = cooki21e.Value
			oneNOOB.Visible = true
	print("Above 100, taking 100 cookies")
			while true do
		wait(1)
		cooke1.Text = cooki21e.Value + 1
	end	
end
end)

2 comments

0

Make sure all your values are correct before anything.

0

I just watched some of the question and I saw this question are upvoted pretty fast so I rushed to here to upvote XD

1 answer

✓ Accepted answer

The problem is that you are not changing the IntValue value in the loop. Add this line of code before line 17 to fix the issue:

cooki21e.Value = cooki21e.Value + 1

Also, I noticed you mention: "When you have 100 cookies or more you can buy a Worker". If that is the intended functionality, then I suggest you change line 10 to this as well:

elseif cooki21e.Value >= 100 then

This will let players buy a worker at 100 rather than 101.

1 comment

0

thanks

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