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

attempt to perform arithmetic on field 'Value' (a string value)?

Asked by 4 years ago

I keep getting this error saying "attempt to perform arithmetic on field 'Value' (a string value)"

local seats = workspace.Seats
local replicatedstorage = game:GetService("ReplicatedStorage")
local num = replicatedstorage:WaitForChild('InfoValue2')

for _,seat in pairs(seats:GetChildren()) do

    if seat:IsA("Seat") then

        seat:GetPropertyChangedSignal("Occupant"):connect(function()

            if seat.Occupant ~= nil then

                num = num.Value + 1 --THIS IS THE LINE I GET THE ERROR FROM.

            else

                num = num.Value - 1

            end

        end)

    end

end

It's suppose to added a number to the value every time I player sits, for an example if there's 2 people sitting down on the seat and another player sits, it's suppose to change the value from 2 to 3. (The String Value changes the text to a UI.)

1 answer

Log in to vote
1
Answered by
Maxis_s 97
4 years ago

The "num" value is a string value, and you cannot perform math on it. What you are trying to do is add/subtract 1 to text, which is impossible.

What you need is a number value, then use the tostring() function on that number value.

You can perform that math on a number value.

This number value can also be a variable, but if you're using multiple scripts that need this value, then I recommend that you add a number value.

Hope this helps!

-Maxis_s

Ad

Answer this question