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

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

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

✓ Accepted answer

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!

4 comments

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?

0

Is the table already made? Is the table's content are string? Did you put a specific index in the table?

0

And is the second indexed string of the table nil or not?

0

i rewrote the script and it works perfectly now! (i still don't know what happened) thank you so much for your help!

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