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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
What datatype is 'Coins'? Hacreey 49 — 4y
0
What is a datatype? NoRainbowGT 14 — 4y

1 answer

Log in to vote
0
Answered by
Gojinhan 353 Moderation Voter
4 years ago

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

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

or just make it a number

Ad

Answer this question