Applying NumberVal.Value to Model name

Currently working on a Sequence system in which the Individual Player has a Value referring to which sequence they are currently at.

Currently, the script works by reading a Value from within the Model itself - However, I want to make it so that it reads the NumberValue from the Model name itself.

The sequence Models are titled: “Sequence#0” etc.

Was thinking that maybe:
if x.Value == model.Name
would of worked, but evidently not. As it’s only the following Digits after # that are actually needed.

Are we able to see your current code.

function ModuleScript.SetUp(Player)


if Obj.Name == "Sequence_Trigger" then

local PlayerSequence = Player.PlayerData.Data["Current_Sequence"]

if Obj.Parent["isSequence"].Value == PlayerSequence.Value then

local FindSequence = Sequences:FindFirstChild("Sequence#"..Obj.Parent["isSequence"].Value)

if FindSequence then

require(FindSequence).Play(Player, Obj)

else end

else return end

else return end



This is the current coding.

You can use string.match with a string pattern:

local name = "SomeName#123"
local sequence = tonumber(name:match("#(.*)"))
print(sequence) --> 123

I recommend against storing information about instances in their name (other than their name), and using a dedicated value instance or data structure to handle this as you are currently doing.


As @Dandystan said I would use string.match as it is the best way to do this sort of thing. Their is another way to do this by using string.sub. This isn’t the best way to do this sort of thing as everything before the sequence number will have to be the same amount of characters long. I would definitely look up the page on the wiki about strings.

You can actually match numbers directly with something such as the following.

local sequence = tonumber(name:match("%d+"))

Though this will not handle decimals.

1 Like

This would be problematic if OP used numbers in their regular model name.

1 Like

I assumed they weren’t, but this is a valid point.