Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

take a model name and cut it in two seperate parts?

Asked by 5 years ago
local id = script.Parent.ID.Value

local myname = game.Workspace:FindFirstChild("MyModel"..id)

I have a long script involving this problem so I created an example for the sake of time. there are models inside the workspace, the first part of the name is what the model is, the other part is the name of the owner of that model:

[[[ "name of model"..players name in a value ]]]

my current problem is I need to get the owner of a specific model but I want to leave the models name out. is there a way to basically cut a string name in half and use it seperately?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

To do this you would use:

string.sub('variable', i, j)

Where 'variable' is the string that you're trying to separate, i is the start of the string that you want to separate and j is where you want the string to stop cutting or just leave it out to get any part of the string after 'i'.

Ex:

local ex = "abcdefghijk"
print(string.sub(ex, 4))

This would print "defghijk" Ex 2:

local ex = "abcdefghijk"
print(string.sub(ex, 4, 8)

This example would print "defgh"

0
thanks mantorok4866 201 — 5y
0
though one more question does this work outside of the quotation marks? mantorok4866 201 — 5y
0
This works only for strings. As long as what you're using is a string in some way, it should work. I'm not 100% sure on what you're asking though Retr0Thief 104 — 5y
Ad

Answer this question