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

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

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

✓ Accepted answer

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

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