What I want to achieve, is have working NPCs that talk. To clarify, talking like in story games, or like this.
The issue, is, I’m just a beginner programmer, and I don’t really know how to script this. I want to get it to work, but if I really can’t, should I make something simpler, or keep trying.
I have looked for solutions just about anywhere I know. I’ve found multiple tutorials, but those either have code that isn’t explained very well, or don’t fit what I need, and are buggy.
I just need help on explaining how, not an entire script written.
Tutorials I have found:
a. This tutorial is difficult, and hard to edit for me. I also don’t really know about the code.
b. This works well, but I want mine to be click-activated, and theirs is also buggy.
Code so far:
I’m sorry if it’s bad or anything.
It obviously doesn’t work, and it’s kind of a mix of my own thing, and a tutorial.
My workspace:
ModuleScript:
local module = {
Dummy = {Page1 = {"Testing Page1, line1", ""}, Page2 = {"", "Testing Page2, Line2"}},
}
return module
Code
Code so far:
local player = game.Players.LocalPlayer
local npcs = workspace.NPCs:GetChildren()
local uis = game:GetService("UserInputService")
local DialogueUI = player.PlayerGui:WaitForChild("DialogueUI")
local bg = DialogueUI.Background
local Dialogue = require(script:WaitForChild("Dialogue"))
local CurrentPage = 1
local CurrentNPC = ""
local Click = CurrentNPC.TalkPart
local function typing(text1, text2)
bg.TextLabel1.Text = ""
bg.TextLabel2.Text = ""
DialogueUI.Enabled = true
local page = CurrentPage
local npc = CurrentNPC
for i = 1, string.len(text1), 1 do
if DialogueUI.Enabled == false or page ~= CurrentPage or npc ~= CurrentNPC then break end
if string.sub(text1, i, i) ~= " " then
bg.TextLabel1.Text = string.sub(text1, 1, i)
wait(0.05)
end
end
wait(0.3)
for i = 1, string.len(text2), 1 do
if DialogueUI.Enabled == false or page ~= CurrentPage or npc ~= CurrentNPC then break end
if string.sub(text1, i, i) ~= " " then
bg.TextLabel2.Text = string.sub(text2, 1, i)
wait(0.05)
end
end
end
Click.MouseClick:Connect(function(key, chat)
if chat then return end
if player.PlayerGui.DialogueUI.Enabled == false then--Start Dialogue
-- CurrentNPC = button.Parent.Parent.Name
bg.NPCName.Text = CurrentNPC
CurrentPage = 1
typing(Dialogue[CurrentNPC]["Page1"][1], Dialogue[CurrentNPC]["Page1"][2])
end
end)
I know it’s terrible, and doesn’t work, I just need some pointers on which direction to go.
Also, should I use a ModuleScript to store all the code?
I don’t really know if doing something is too much to ask for, for a programmer like me.
If you need extra info on what I'm trying to get it to look like
Things I’m trying to get it to do:
Cannot talk to multiple NPCs at once
Ability to talk with multiple “pages”
Organized
Thank you!