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

how can i make this have multiple dialog + disappear after a little?

Asked by
omorizz 50
2 years ago

a person gave me this wonderful script (couldnt have done it with out ya) but i can't figure out how to make it have multiple dialogs in one. (multiple sentences in one chat) and it also stays on screen forever, it needs to fade after a small time. how can i achieve these things?

this is the script inside the textlabel

local RS = game:GetService("ReplicatedStorage")
local Dialogue = RS:WaitForChild("Dialogue")

local Waits = {
    "!",
    ".",
    "?",
    ";",
    ":",
    ","
}

local TextLabel = script.Parent

function setText(Text)

    for i = 1, #Text do
        TextLabel.Text = string.sub(Text, 1, i)

        for Index, Breakers in pairs(Waits) do
            if string.sub(TextLabel.Text, i, i) == Breakers then
                task.wait(0.2)
            end
        end
        task.wait(0.1)
    end

end



Dialogue.OnClientEvent:Connect(function(msg)
    TextLabel.Parent.Parent.Enabled = true
    setText(msg)
end)

this is the script inside the proximityprompt

local RS = game:GetService("ReplicatedStorage")
local DialogueEvent = RS:WaitForChild("Dialogue")

local Prox = script.Parent

Prox.Triggered:Connect(function(plr)
    DialogueEvent:FireClient(plr, "hey there, want some snacks")
end)

also, it has a remoteevent in replicated storage

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

You can use a table with the strings in it. And you can set up a new number variable.

local RS = game:GetService("ReplicatedStorage")
local Dialogue = RS:WaitForChild("Dialogue")

local Waits = {
    "!",
    ".",
    "?",
    ";",
    ":",
    ","
}

local TextLabel = script.Parent

local DialogueTables = {
    "Hey there! I am the first dialogue to be shown!",
    "And I'm second!"
}

local Speed

function setText(Text)

    for i = 1, #Text do
        Speed = (#Text * 0.1)

        TextLabel.Text = string.sub(Text, 1, i)

        for Index, Breakers in pairs(Waits) do
            if string.sub(TextLabel.Text, i, i) == Breakers then
                task.wait(0.2)
            end
        end
        task.wait(0.1)
    end

end

Dialogue.OnClientEvent:Connect(function()
    TextLabel.Parent.Parent.Enabled = true
    setText(DialogueTables[1])
    task.wait(tonumber(Speed + 1)) -- Using tonumber() to make sure it's a number, and adding a 1 is to make sure it doesn't pop off and move onto the next sentence immediately, which might be annoying if you haven't finished reading it
    setText(DialogueTables[2])
    task.wait(tonumber(Speed + 1))
    TextLabel.Parent.Parent.Enabled = false
end)

Of course, there MIGHT be some flaws in this script. If there is, please let me know and I'll try to improve!

0
i keep getting this output error message: Players.omorizz.PlayerGui.ScreenGui.Frame.TextLabel.LocalScript:43: attempt to index nil with number , im not sure whats wrong? omorizz 50 — 2y
0
Is the table already made? Is the table's content are string? Did you put a specific index in the table? NotThatFamouss 605 — 2y
0
And is the second indexed string of the table nil or not? NotThatFamouss 605 — 2y
0
i rewrote the script and it works perfectly now! (i still don't know what happened) thank you so much for your help! omorizz 50 — 2y
Ad

Answer this question