Subtract number from string

i saved a string in my datastore wich can be split in 4 strings
i don’t know how to use math for strings though, i’ve tried different ways but none of these seem to be valid

function Click()
	local value=script.Parent.Parent.Parent.Parent.Gamedata.Gameplay.Value
	
	local splot=string.split(value,";")
	
	local cash,exp,lvl,houses= splot[1],splot[2],splot[3],splot[4]
	
	if tonumber(cash)==nil then
		
	value=tostring(script.Parent.Value.Value)..";"..tostring(exp)..";"..tostring(lvl)..";"..tostring(houses)	
		
	else		
	
		value=tostring(tonumber(cash)+1000)..";"..tostring(exp)..";"..tostring(lvl)..";"..tostring(houses)	
		
		
		
	end	
	
end
script.Parent.MouseButton1Down:connect(Click)

i really don’t know what i’m doing wrong, are there any possible posts that can help me?

Hello!
It’s a little bit unclear to me what math you want to do.
Can you please clarify?

i basically saved a string in my datastore, i’m trying to make a gui button that can divide the string in 4 parts and increase the first one by 1000
the thing is it doesn’t seem to change anything

function Click()
	local value = [...]
	
	local cash, level, exp, houses = string.split(value, ";")
	
	if not tonumber(cash) then
            cash = tonumber(cash) + 1000
	    value = tonumber(cash + 1000)..";"..tonumber(level)..";"..tonumber(exp)..";"..tonumber(houses)
	end
end
script.Parent.MouseButton1Down:connect(Click)

Basic implementation, could be better ways but I didn’t really care.

I see your problem now. The problem is that your value variable is a reference to the value, not the object itself. So, if you take a step back to the “Gameplay” object and then do Gameplay.Value = (whatever you want) it should work then.

For example

function Click()
	local value=script.Parent.Parent.Parent.Parent.Gamedata.Gameplay.Value
    local gameplay = script.Parent.Parent.Parent.Parent.Gamedata.Gameplay
	
	local splot=string.split(value,";")
	
	local cash,exp,lvl,houses= splot[1],splot[2],splot[3],splot[4]
	
	if tonumber(cash)==nil then
		
	 gameplay.Value=tostring(script.Parent.Value.Value)..";"..tostring(exp)..";"..tostring(lvl)..";"..tostring(houses)	
	else		
	
		gameplay.Value=tostring(tonumber(cash)+1000)..";"..tostring(exp)..";"..tostring(lvl)..";"..tostring(houses)	
		
		
		
	end	
	
end
script.Parent.MouseButton1Down:connect(Click)

Let me know how it goes!

1 Like