Hi, I’m looking for a way to create an interaction between Players and NPCs in my game - This is primarily theorised at this moment in time however I’ve had some concepts I’d like to run past others.
My main idea is to have a Main Gui, inside will have the frame / layout of the basic chat boxes and such as well as a LocalScript. This script will detect if the Player’s Mouse.Target has an Interact module - if so, it’ll fire it.
However, as I plan for the text to enter in a type-write manner, is there any way of doing this where the module detects when to start a new line / paragraph or remove all text altogether to start a “new page”.
If i understood your post, every interactable would have a module script that would get required when interacted with? Then the UI would be filled with information from the module?
The frustrating part about implementing a typewriter would be how the text scales. If you want to create a dialogue gui that works cross-platform, the easy way out would be to enable textscaled. However, a typewriting effect + textscaling is wacky because the text would rapidly be changing size.
I suppose you could create a custom algorithm that takes in the absolute size of the gui and divides that by the number of characters you want per line. Use this to determine the size of the font.
Then, change the text label settings so that the text begins in the top left of the textbox. Use a for loop to iterate from i=1 to the size of the string, displaying string.sub(string,1,i) in the textbox. Boom
This is actually easy to implement, but as @idkhowtocode was describing, it looks a bit wonky with text scaling, example here:
local UI = script.Parent.NPCBox
local Dialog = "Hello this is a test dialog that shows the typewriter effect!"
for i = 1, #Dialog do
UI.Text = string.sub(Dialog, 1, i)
wait(0.01)
end