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

[string.sub help]

Can anyone see a problem with what is indexed below? I have made sure the variables are correctly found, I have tested this script in game with a report-error thing, and it doesn't show an error. (Yes, there is more to the script, this is just a piece of it.)

			elseif string.sub(string.lower(msg),1,13) == "openFrontDoor" then
				mdoor.Transparency = 0.4
				mdoor.CanCollide = false
			elseif string.sub(string.lower(msg),1,14) == "closeFrontDoor" then
				mdoor.Transparency = 0
				mdoor.CanCollide = true

2 answers

✓ Accepted answer
elseif string.sub(string.lower(msg),1,13) == "openfrontdoor" then
    mdoor.Transparency = 0.4
    mdoor.CanCollide = false
elseif string.sub(string.lower(msg),1,14) == "closefrontdoor" then
    mdoor.Transparency = 0
    mdoor.CanCollide = true

Your script was not working because you were calling string.lower on the message, which makes all letters lowercase, then comparing it to a string that contains capital letters.

2 comments

0

Thanks!

0

msg:lower():sub(1,13) is a much shorter way to write the same thing!

There's supposed to be a space in between else and if. I know I didn't fully answer this because I'm new to scripting also, but this is what I know.

else if string.sub(string.lower(msg),1,13) == "openFrontDoor" then
    mdoor.Transparency = 0.4
    mdoor.CanCollide = false
else if string.sub(string.lower(msg),1,14) == "closeFrontDoor" then
    mdoor.Transparency = 0
    mdoor.CanCollide = true

2 comments

0

That is false. It is elseif, but can also be "else if." As far in this situation, the difference does not matter.

0

Actually, using else if in this situation is a bad idea and requires more ends.

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