I’ve been working on an NPC talking system, and I’m basically done. However, I’m having an issue.
It’s pretty much the last thing I need to do.
To finish up, I’m trying to implement this system where it checks how many pages there are. I set mine to 3 pages of text, but it still shows the 4th page as an empty nothing.
(You will need to view the code)
ModuleScript:
local talk = {}
script.Parent.Enabled = false
talk.talkfunction = function(player)
-- local dbounce = false
script.Parent.Enabled = false
-- print(script.Parent.Enabled)
local textlabel1 = script.Parent:WaitForChild("Main"):WaitForChild("Text1")
local textlabel2 = script.Parent:WaitForChild("Main"):WaitForChild("Text2")
--local lines = require:(game.StarterPlayer.StarterCharacterScripts:WaitForChild(Lines)
local npcs = game.Workspace.NPCs
local Dummy = npcs.Dummy
local page = 1
local proceed = script.Parent:WaitForChild("Main"):WaitForChild("Proceed")
local pagedone = false
local lastpage = false
local ispage2 = true
local ispage3 = true
local ispage4 = false
local txt1 = "text test so i can copy this"
local txt2 = "text test so i can copy this"
local txt3 = "text test so i can copy this"
local txt4 = "text test so i can copy this"
local txt5 = "text test so i can copy this"
local txt6 = "text test so i can copy this"
local txt7 = "text test so i can copy this"
local txt8 = "text test so i can copy this"
local function typewrite(object,text)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
game:GetService("RunService").Stepped:Wait(0.001)
end
end
local function dummyText(player)
local dialoguefinished = false
if script.Parent.Enabled == false then --if script.Parent.Enabled and dbounce == false then
-- dbounce = true
--warn("Began")
local char = player.Character
local hum = char.Humanoid
hum.JumpPower = 0
hum.WalkSpeed = 0
hum.AutoRotate = false
page = 1
pagedone = false
lastpage = false
script.Parent.Enabled = true
-- dialoguefinished = false
typewrite(textlabel1,txt1)
typewrite(textlabel2,txt2)
pagedone = true
local proceedevent
proceedevent = proceed.MouseButton1Click:Connect(function()
if lastpage and pagedone then
script.Parent.Enabled = false
textlabel1.Text = ""
textlabel2.Text = ""
hum.JumpPower = 50
hum.WalkSpeed = 16
hum.AutoRotate = true
page = 1
pagedone = false
lastpage = false
dialoguefinished = true
proceedevent:Disconnect()
-- dbounce = false
elseif page ==1 and pagedone and ispage2 then
textlabel1.Text = ""
textlabel2.Text = ""
page = 2
pagedone = false
lastpage = false
typewrite(textlabel1, txt3)
typewrite(textlabel2, txt4)
pagedone = true
pagedone = true
elseif page == 2 and pagedone and ispage3 then
textlabel1.Text = ""
textlabel2.Text = ""
pagedone = false
page = 3
typewrite(textlabel1, txt5)
typewrite(textlabel2, txt6)
pagedone = true
--page = 1
-- lastpage = true
elseif page == 3 and pagedone and ispage4 then
textlabel1.Text = ""
textlabel2.Text = ""
pagedone = false
page = 4
typewrite(textlabel1, txt7)
typewrite(textlabel2, txt8)
pagedone = true
page = 1
lastpage = true
elseif page == 3 and pagedone and not ispage4 then
lastpage = true
page = 1
pagedone = true
textlabel1.Text = ""
textlabel2.Text = ""
elseif page == 2 and pagedone and not ispage3 then
lastpage = true
page = 1
pagedone = true
textlabel1.Text = ""
textlabel2.Text = ""
elseif page == 1 and pagedone and not ispage2 then
lastpage = true
page = 1
pagedone = true
textlabel1.Text = ""
textlabel2.Text = ""
end
end)
repeat
wait(0.05)
until dialoguefinished == true
else
end
end
dummyText(player)
end
return talk
LocalScript:
local talkmodule = require(script.Parent.TalkModule)
local npcs = game.Workspace.NPCs
local Dummy = npcs.Dummy
local player = game.Players.LocalPlayer
local dbounce = false
Dummy.Click.ClickDetector.MouseClick:Connect(function()
if dbounce == false then
dbounce = true
talkmodule.talkfunction(player)
dbounce = false
end
end)
If anyone could tell me how to improve my code too, that would be a huge help!
I honestly think my “Other idea” would work much better, but I have no idea what to do, so yeah. Any help with that would be great!
My other idea
I’ve been thinking about a system where there’s a variable like “pageamount”, and the talk page code runs once for each page, but I don’t know how to do that. I would appreciate help on that too!
Edit: I’ve decided to go with the other idea.
Thanks!