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

Can someone help me with this string thing?

Asked by
Dr_Doge 100
9 years ago

So Im making a Say command that will let you add an AI Voice. Im having trouble with this part of the script.

CAP stands for Check And Play The cap function will check the Letter and match it with the corresponding sound, then play the sound.

01function Say(fullmsg)
02lowermsg=string.lower(fullmsg)
03msg=string.gsub(lowermsg,"ing","A")-- A will play the ing sound
04msg=string.gsub(msg,"ch","B") -- B will play the ch sound
05local msg=string.gsub(msg,"wh","C") -- C will play the wh sound
06Amount = string.len(msg)
07Number=1
08repeat
09Number=Number+1
10cap(string.sub(msg,Number))  -- I think my problem is here
11until
12Number==Amount
13end

I have a feeling the problem is the function calls more than one letter. Can someone help me? Just ask me in chat with "@fancyboby47" if you need further explanations!

Thank you!

1 answer

Log in to vote
0
Answered by 9 years ago

Remember, that when the function is being called, you are asking if that "fullmsg" is being messaged. (Also don't forget that iterating your code is more organized).

01-- put this in a local script
02 
03local player = game.Players.LocalPlayer
04local A = Instance.new("Sound")
05A.Parent = game.Workspace
06A.SoundId = "..."   -- make this the id of the sound, and do this for each sound
07-- list the rest of the sounds here --
08 
09 
10player.Chatted:connect(function(fullmsg)        -- when the player chats, do this function
11    lowermsg=string.lower(fullmsg)
12 
13    if lowermsg == "ing" then
14        A:Play()
15    end
16    if lowermsg == "ch" then
17        B:Play()
18    end 
19end)

I hope this helps. I'm not quite sure what you are trying to do with the "cap(string.sub(msg,Number))" though...

~N

0
Look, I understand what Chatted and connect are, and I know very well how to use them. The reason I did't use them is because I dont want this function to be just for Chat. Also, your code is far from what Im trying to do. I think what Im trying to do is over your level, so if you dont understand the code, please dont try to correct me. Thanks for the much appreciated effort though. Dr_Doge 100 — 9y
Ad

Answer this question