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.
function ModuleScript.SetUp(Player)
Player.Character.Humanoid.Touched:Connect(function(Obj)
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
end)
end
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.