I’m making a dialog system and I need a “click to advance” for it, which is something I’ve always struggled with.
I found out how to do it, but it’s not a great method nor is it very efficient.
local textlabel = script.Parent:WaitForChild("TextLabel")
local function write(object,text,length)
for i=1,#text,1 do
object.Text=string.sub(text,1,i)
wait(length)
end
end
write(textlabel,"text 1",0.2)
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType==Enum.UserInputType.MouseButton1 then
write(textlabel,"text 2",0.2)
end
end)
I use a function that detects if the player has pressed the left mouse button, then make it so that if it’s the case, progress to the next line of dialog. But if I have more than one of these, as in:
write(textlabel,"text 1",0.2)
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType==Enum.UserInputType.MouseButton1 then
write(textlabel,"text 2",0.2)
if input.UserInputType==Enum.UserInputType.MouseButton1 then
write(textlabel,"text 3",0.2)
end
end
end)
Not only does it get very messy, but you’ll obviously see a problem: Since multiple functions are always looking out for the same input, obviously all functions will trigger at one once I press the left mouse button.
I’m a coding amateur and have absolutely no idea how to tackle this; I need help.