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

Keep getting "attempt to perform arithmetic on a string value"?

Error: Players.NoRainbowGT.PlayerGui.Main.+Coins:25: attempt to perform arithmetic on a string value

local suffixes = {'','K','M','B','T','qd','Qn','sx','Sp','O','N','de','Ud','DD','tdD','qdD','QnD','sxD','SpD','OcD','NvD','Vgn','UVg','DVg','TVg','qtV','QnV','SeV','SPG','OVG','NVG','TGN','UTG','DTG','tsTG','qtTG','QnTG','ssTG','SpTG','OcTG','NoAG','UnAG','DuAG','TeAG','QdAG','QnAG','SxAG','SpAG','OcAG','NvAG','CT'}
local function format(val)
    for i=1, #suffixes do
        if tonumber(val) < 10^(i*3) then
            return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
        end
    end
end
 
local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local Coins = leaderstats:WaitForChild("Coins")

local dif = 0
delay(.25, function()
    dif = Coins.Value
end)

Coins.Changed:Connect(function()
    if dif ~= Coins.Value and dif <= Coins.Value then
       local random = math.random(1, 900)
       local xnew = random / 1000
       local new = script:WaitForChild("Coin"):Clone()
       new:WaitForChild("CoinInfo").Text = "+".. (format(Coins.Value)) -  dif
       new.Position = UDim2.new(xnew, 0, 1, 0)
       new.Parent = script.Parent
       dif = Coins.Value
       wait(0.1)
       new:TweenPosition(UDim2.new(new.Position.X, 0, -0.1, 0))
       new.Parent = nil
   end
end)

2 comments

0

What datatype is 'Coins'?

0

What is a datatype?

1 answer

You can't do math on a string...

Either use tonumber(stringvalueexample) while ur trying to do it

or just make it a number

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