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

How do I detect the space inbetween?

(Sorry for my bad English in advance) I made a script which checks a string then writes it down on a textlabel. I also added a sound which then is played while the text is being writen in the textlabel (just like in undertale,pokemon etc). Now the problem lies in texts with space's within it. My script doesn't detect these spaces so it plays a sound when the script writes empty spaces (I only wanted to have it make a set noise when a letter is written and not a empty space).

localscript:

wait(3)
plr = game.Players.LocalPlayer
S = Instance.new("Sound",plr.Character.LowerTorso)
S.SoundId = "rbxassetid://4662452515"
text = "Hey there :D"
wait(1)
print("Starting!")
for i = 1, string.len(text) do
    wait(.05)
    if text[i] == " " then --- spacebar
        print("empty text found")
    else
    S:Play()
    end
end

As you can see I tried using

if text[i] == " " then print("empty text found") else blablabla

no print "empty text found" have been found in the outputbox can somebody explain why

1 comment

0

the local script is placed in the StarterPack

1 answer

You could use a split method in a way.

wait(3)
plr = game.Players.LocalPlayer
S = Instance.new("Sound",plr.Character.LowerTorso)
S.SoundId = "rbxassetid://4662452515"
text = "Hey there :D"
wait(1)
print("Starting!")
local txtTable = text:split(" ") --//Splits the text whenever it spots a space in between
for _,v in pairs (txtTable) do
	S:Play()
end

If you wanted to play the sound letter by letter, you will have to do it like this.

wait(3)
plr = game.Players.LocalPlayer
S = Instance.new("Sound",plr.Character.LowerTorso)
S.SoundId = "rbxassetid://4662452515"
text = "Hey there :D"
wait(1)
print("Starting!")
local txtTable = text:split("") --//Splits the text whenever it spots a nothing, therefore splits all characters apart
for _,v in pairs (txtTable) do
	if v ~= " " then --//If the character does not = a space.
		S:Play()
	end
end

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