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

Why is my cash value not going up by 1 every 10 clicks?

local CashOnClick = 1 clickdetector.MouseClick:Connect(function() clickdetector.Parent:Destroy() for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("leaderstats") then v.leaderstats['Apples Clicked'].Value = v.leaderstats['Apples Clicked'].Value + 1 v.leaderstats['Cash'].Value = v.leaderstats['Cash'].Value + 1 if v.leaderstats['Apples Clicked'].Value == 10 then v.leaderstats['Cash'].Value = CashOnClick.Value + 1 end end end end)

I have not included the whole script but im attempting to make it so every time "Apples Clicked"'s value goes up by 10, the CashOnClick Value goes up by 1, therefor increasing the amount of cash gained per click. Yet It gives me the error "attempt to index global 'CashOnClick' (a number value)"

6 comments

0

Don't forget to accept my answer if it helps out. It gives us both the reps we deserve.

0

What exactly are you trying to do every 10 clicks then?

0

I have edited my answer. Please check the update.

0

Made another edit. But please do try to solve it yourself next time. Try it now. You can change the + 1 in line 10 to whatever number you want it to increase by

0

How does it not work.

0

Made a LAST edit.

1 answer

That is because CashOnClick is literally a number. Not an IntValue/NumberValue. Remove the .Value and it will fix the problem. Now for the second question if you want to make the cash go up every 10 clicks use the modulus operator %. It divides two numbers and instead of returning the quotient, it will return the remainder instead.

Examples:

print(12 % 6) -- 0 (12/6 no remainder)
print(300 % 200) -- 100 (200 goes into 300 only once, it going twice results in a remainder of 100

Final product

local CashOnClick = 1 

clickdetector.MouseClick:Connect(function() 
    clickdetector.Parent:Destroy() 
    for i,v in pairs(game.Players:GetPlayers()) do 
        if v:FindFirstChild('leaderstats') then 
            v.leaderstats['Apples Clicked'].Value = v.leaderstats['Apples Clicked'].Value + 1
            if v.leaderstats['Apples Clicked'].Value % 10 == 0 then
                CashOnClick = CashOnClick + 1
                v.leaderstats['Cash'].Value = v.leaderstats['Cash'].Value + (CashOnClick + 1)
            end 
        end 
    end 
end)

So if the number modulated by 10 is 0 that means it is divisible by 10.

3 comments

0

this just sets the cash leaderstat to 2 instead of keeping the original value and just making it so every 10 apples clicked, you get 1 more cash per click i.e, if i get 10 apples, instead of 1 cash per click, it adds 1 more and i get 2 cash per click

0

Still dosnt work, after you get 10 apples clicked, sets your cash to 12 but dosnt increase the amount of cash you get per click

0

dosnt work but thanks i guess

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