I am trying to get the letters/numbers at the end of a string after a ':' (ex: test:56, I would want 56). I tried using string match but it just shows as nil.

local RepStore = game:GetService("ReplicatedStorage")
local vote = RepStore:WaitForChild("Remotes"):WaitForChild("Vote")
local votes = game:GetService("ServerStorage"):WaitForChild("Votes")

vote.OnServerEvent:Connect(function(_p, v, pv, pvn, n)
	assert(type(v) == "number", "v must be a number")
	assert(type(pv) == "number", "pv must be a number")
	
	if pv == 0 then
		votes[v].Value = n.."_1" 
	else
		print(string.match(votes[pv].Value, ":(.*)")) -- Output: nil
		votes[pv].Value = pvn.."_"..string.match(votes[pv].Value, ":(.*)") - 1
		votes[v].Value = n.."_"..string.match(votes[v].Value, ":(.*)") + 1 
	end
end)

2 comments

0

We need context on what you're actually trying to do

0

you're attempting string.match on a Number Value, right? I don't think that's how it works. i think this would be the proper way to use string.match: local string = "bob" if string.match(string,"ob",1) then print("found ob in bob") end