This script 'ere finds the B0 from the IntValue called "pimppi". It increases the number after B by 2. But the issue is, how can I not affect the other values of pimppi? Line 16 nulls all the other values when B0 is changed. I could do the same for the other values in pimppi as I did to B0 here, but later on, that would be messy as hell. How do I do it with string.match? This is a really messy script anyway, I'm just trying to learn string manipulation!
Thank ye!
local clickDetector = script.Parent.ClickDetector local number = "%d+" local letter = "%w" local stats = script.Parent.pimppi local s = stats.Value local function onMouseClick(player) local Kappa = ( string.match(s, "B%w+") ) local Heathen = (string.match(Kappa, number) ) local Stender = (string.match(Kappa, letter) ) local bob = ("".. Stender .."".. Heathen + 2 .."") Kappa = bob s = ("A0 ".. Kappa .." C0 D0 E0") print(Heathen) print(Stender) print("Kappa: " ..Kappa) print(bob) print(s) end clickDetector.MouseClick:connect(onMouseClick)
If you want to replace part of a string then use string.gsub
.
With your string "A0 B0 C0 D0 E0", if you want to only match "B0" and increase the number by 1, then replace it and add one through the function argument.
local s = stats.Value:gsub("B(%d+)",function(n)return"B"..(tonumber(n)+1)end)
This captures B(%d+) which is B following any number with one or more digits, then captures that number and passes it to the function which adds one to it and returns the new string replacement.