Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Not looping when forever after a certain number?

Asked by 4 years ago
Edited 4 years ago

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)
0
Make sure all your values are correct before anything. JayShepherdMD 147 — 4y
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 Xapelize 2658 — 4y

1 answer

Log in to vote
1
Answered by
cfiredog 274 Moderation Voter
4 years ago

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.

0
thanks Error_404isGAMING 30 — 4y
Ad

Answer this question