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

Dialogue module marking everything as punctuation?

Asked by 6 years ago

so i have this modulescript here that will check if the last character in the text is a period, question mark, exclamation point, comma, colon, or semicolon, but for some reason, it's marking every character as a period/question mark/exclamation point. i think this might have to do with the or statements? here's the code:

local player

wait(1)

player = game.Players:FindFirstChildWhichIsA("Player")
local db = player.PlayerGui.ScreenGui.DialogueBox

function Dialogue(text)
    for i=0,string.len(text) do
        db.Text.Text = string.sub(text, 1, i)
        player.PlayerGui.Beep:Play()
        if string.sub(db.Text.Text, string.len(db.Text.Text)) == "." or "?" or "!" then
            wait(1)
        elseif string.sub(db.Text.Text, string.len(db.Text.Text)) == "," or ";" or ":" then
            wait(0.5)
        end
        wait()
    end
    wait(1)
    game.ReplicatedStorage.DProgressed.OnServerEvent:Wait()
end

return Dialogue

1 answer

Log in to vote
0
Answered by 6 years ago

The problem is your if statements. When using "or", the code searches for a new condition after every "or".

It should look like this:

        if string.sub(db.Text.Text, string.len(db.Text.Text)) == "." or string.sub(db.Text.Text, string.len(db.Text.Text)) == "?" or string.sub(db.Text.Text, string.len(db.Text.Text)) == "!" then
13
            wait(1)
14
        elseif string.sub(db.Text.Text, string.len(db.Text.Text)) == "," or string.sub(db.Text.Text, string.len(db.Text.Text)) == ";" or string.sub(db.Text.Text, string.len(db.Text.Text)) == ":" then

I apologize for the formatting. My iPad is not made for coding (or typing, really). This should solve your problem.

0
it worked, thank you! Reziztor 4 — 6y
Ad

Answer this question