Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with string.sub on Names? No errors or anything. Confused

if v.Name == string.sub("Room", 1,4) then --- Change "Room" to whatever the first for letters of each hotel room name is
    print("Detected Name")
end

This script doesn't seem to do anything. The first 4 letters of v is definitely "Room" No errors or anything, just nothing. Help?

1 answer

✓ Accepted answer

Looks like you're using your sub function on the wrong string. It's v that you want to get the first 4 letter from, not "Room". Here, try this instead:

-- To shorten your code, you can use functions from the string library as methods. This is up to you, however.
if v.Name:sub(1,4) == "Room" then
	print("Detected name")
end

This way you're getting the first 4 letters from whatever your input is, instead of just comparing your input to match "Room". Hope that's what you're looking for, let me know if you have any questions.

This discussion is preserved as it was. New answers, comments, and votes are closed.