-
What do you want to achieve? Keep it simple and clear!
Hey, I am trying to make a dialogue system for a side project. -
What is the issue? Include screenshots / videos if possible!
I keep getting this error message, and I have tried just about everything in my power to fix it, but it works to no avail.
2023-12-28 16-46-05 -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried reading online solutions, though there was nothing that I could find applicable.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is my client script:
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TalkEvent = ReplicatedStorage:WaitForChild("TalkEvent")
local main = script.Parent.Main
local choicesFrame = main.ChoicesFrame
local nameLabel = main.NameFrame.Label
local dialogLabel = main.DialogFrame.Label
local choicesTemplate = script.ChoiceTemplate
local cameraFrame = main.CameraFrame
local currentNPC = nil
local storedChoices = {}
local function typeWrite(text, label, info)
label.Text = ""
for i, v in text:split("") do
label.Text = label.Text..v
task.wait(info.TypeRate.Value) -- 1200bpm, variable can change
end
end
local function endDialog(info)
for i, child in pairs(choicesFrame:GetChildren()) do
-- Clears out choices from previous dialogue
if child:IsA("TextButton") then
child:Destroy()
end
end
typeWrite(info.LeaveMessage, dialogLabel, info.TypeRate)
task.wait(0.5)
currentNPC.HumanoidRootPart.ProximityPrompt.Enabled = true
task.wait(1)
main.Visible = false
nameLabel.Text = ""
dialogLabel.Text = ""
storedChoices = {}
currentNPC = nil
end
local function nextDialog(info, lastChoice)
for i, child in pairs(choicesFrame:GetChildren()) do
-- Clears out choices from previous dialogue
if child:IsA("TextButton") then
child:Destroy()
end
end
local dialog
if lastChoice then
if lastChoice.Next then
dialog = info.Dialog[lastChoice.Next]
else
endDialog(info)
end
else
dialog = info.Dialog[1]
end
if not dialog then return end
typeWrite(info.LeaveMessage, dialogLabel, info.TypeRate)
if dialog.Choices and (#dialog.Choices > 0 or #storedChoices > 0 ) then
for i, choice in pairs(storedChoices) do
local clone = choicesTemplate:Clone()
clone.Parent = choicesFrame
clone.Name = choice.Text
clone.Label.Text = choice.Text
clone.MouseButton1Click:Connect(function()
storedChoices[i] = nil
nextDialog(info, choice)
end)
end
for i, choice in pairs(dialog.Choices) do
local clone = choicesTemplate:Clone()
clone.Parent = choicesFrame
clone.Name = choice.Text
clone.Label.Text = choice.Text
if choice.Follow == true then
storedChoices[i] = choice
end
clone.MouseButton1Click:Connect(function()
storedChoices[i] = nil
nextDialog(info, choice)
end)
end
local leaveButton = choicesTemplate:Clone()
leaveButton.Parent = choicesFrame
leaveButton.Name = "Leave"
leaveButton.Label.Text = "Goodbye"
leaveButton.MouseButton1Click:Connect(function()
-- Ends the conversation + removes the dialogue
endDialog(info)
end)
else
task.wait(1)
if dialog.Next then
nextDialog(info, dialog)
else
-- Ends the conversation
endDialog(info)
end
end
end
TalkEvent.OnClientEvent:Connect(function(npc, info, cameraCF)
if currentNPC == nil and npc then
currentNPC = npc
nameLabel.Text = npc.Name
dialogLabel.Text = ""
storedChoices = {}
for i, child in pairs(choicesFrame:GetChildren()) do
-- Clears out choices from previous dialogue
if child:IsA("TextButton") then
child:Destroy()
end
end
if cameraCF then
npc.HumanoidRootPart.ProximityPrompt.Enabled = false
local camera = Instance.new("Camera")
local CFrameValue = Instance.new("CFrameValue")
camera.CameraType = Enum.CameraType.Scriptable
camera.Parent = cameraFrame
camera.CFrame = cameraCF
end
main.Position = UDim2.new(0, 0, 1, 0)
main.Visible = true
main:TweenPosition(UDim2.new(0, 0, 0, 0))
task.wait(1)
nextDialog(info, nil)
end
end)
Here is my Info module script:
local Info = {}
Info.LeaveMessage = "Goodbye"
Info.CameraDistance = 3
Info.TypeRate = 0.05
Info.Dialog = {
[1] = {Text = "Hello, how are you?";
Choices = {
[1] = {Text = "Bad"};
[2] = {Text = "I'm great, how are you?"; Next = 2};
}
};
[2] = {Text = "I'm decent, thanks for asking";
Choices = {
[1] = {Text = "What's your name?"; Next = 3, Follow = true};
[2] = {Text = "What's your favorite color?"; Next = 4, Follow = true};
}
};
[3] = {Text = "My name is dummy";
Choices = {
};
};
[4] = {Text = "Yellow";
Choices = {};
}
}
return Info
(there’s another server script used, but i don’t think that it’s needed here)
Thanks in advance for reading this