So i tried to simplify this by putting scripts in each npc model which return the content table when it’s interact remotefunction is invoked but i have reaached a point where i want to use functions but dont know where to put them. did i just make my life harder?
heres the main localscript in the dialoguestorage
local Players = game:GetService("Players")
local DialoguesModule = require(script.Parent.Parent.Main:WaitForChild("DialoguesModule")) -- References the DialoguesModule to run DialoguesModule.CreateDialogue
local NPCs = workspace:WaitForChild("NPCs")
local lclPlayer = Players.LocalPlayer
for _, npc in pairs(NPCs:GetChildren()) do
local canInteract = npc:FindFirstChild("Interact")
if canInteract then
local proximityPrompt = npc:WaitForChild("Torso"):WaitForChild("ProximityPrompt")
proximityPrompt.Triggered:Connect(function()
local interactFunc = npc:WaitForChild("Interact")
local contentTable = interactFunc:InvokeServer(lclPlayer.leaderstats.Level.Value) -- Calls the interact function and stores the returned table in contentTable
DialoguesModule.CreateDialogue(contentTable)
end)
end
end
and heres one of my npc scripts
local npc = script.Parent
local hum = npc:WaitForChild("Humanoid")
local idleAnim = Instance.new('Animation')
idleAnim.AnimationId = 'rbxassetid://86755365089343'
local idleAnimTrack = hum:LoadAnimation(idleAnim)
idleAnimTrack:Play()
local function GiveSpecial()
print('function fired')
end
local interactFunc = npc:WaitForChild("Interact")
interactFunc.OnServerInvoke = function(player, level)
local tableContent = {
Content = {
InitialLayer = "Layer1", -- Which layer to start the dialogue on
DialogueTitle = npc.Name, -- The starting title of the Dialogue
DialogueFrame = "DialogueFrame", -- Which DialogueFrame to use. Set to a custom one if you're using one. ("DialogueFrame" is the default.)
ReplyFrame = "Reply", -- Which ReplyFrame to use if you're using a custom one. ("Reply" is the default.)
Settings = {
Typewriter = true, -- Enable/Disable the typewriter. The typewriter writes every individual letter instead of displaying the text in full instantly.
TypewriterSpeed = 0.01, -- How fast text is displayed on the typewriter.
SpecialTypewriterSpeed = 0.5, -- How fast text is displayed for special characters. (. , ! ? ")
TypewriterSound = "rbxassetid://9126065502", -- Sound to play each time a letter is wrote. Format as "rbxassetid://000" and not just a number.
TypewriterSoundPitch = 1, -- Default is 1. TypewriterSoundRNGPitch must be disabled for this to work.
TypewriterSoundRNGPitch = false, -- Set a random pitch between 0.8 and 1.2 each time a letter is wrote.
Autoscroll = 0, -- 0 disables autoscroll. If the player doesn't click continue after the specified time, the dialogue moves to the next piece of content
DialogueWalkSpeed = 0, -- The WalkSpeed when inside the dialogue. Set to nil to keep the defailt WalkSpeed.
CinematicBars = false, -- Adds some cinematic bars when in the dialogue. Recommended if you're using the Cinematic skin.
BackgroundSound = nil, -- Sound to play for the duration of the dialogue. Format as "rbxassetid://000" and not just a number.
BackgroundSoundVol = 0.1, -- Volume of the BackgroundSound.
DisableBackpack = true, -- Disables the players backpack when in the dialogue.
DisableChat = false, -- Disables the chat when in the dialogue.
DisableLeaderboard = false, -- Disables the leaderboard when in the dialogue.
ContinueButtonVisibleDuringReply = false, -- Should the continue button be visible when replies are visible?
ContinueButtonVisibleDuringTypewriter = false, -- Should the continue button be visible when the typewriter is writing?
ContinueTextTransparency = 0.5, -- The transparency of the Continue text when the continue button is unable to be clicked.
DialogueCam = nil, -- Set to a part instance and it will change the players camera to that part for the duration of the dialogue
StopDialogueOnDeath = true, -- If the players humanoid dies, the dialogue will stop.
InteractWithDialogueWhendead = false -- Can the player start the dialogue when they are dead?
},
Layer1 = { -- This is the first layer.
DialogueContent = {"Greeting's young one. Sun's at its peak today.",}, -- This is what will be displayed on the Dialogue. Seperate content by commas.
DialogueSounds = {}, -- Put in a SoundId to play per piece of content. If you don't want a sound for a piece of content then just set it as nil. Do not format as "rbxassetid://000" and just use the Soundid.
DialogueImage = npc, -- This is the image that will be displayed, you can probably use it as an icon of your NPC. Not all Dialogue Skins support this.
LayerTitle = nil, -- Set the text of your title again. This is the first layer so this isn't really needed, but you might want it for your 2nd layer.
Replies = { -- This is a table of stuff the player can reply with to the Dialogue. They always appear at the last piece of content on the layer. ("Content2" in this case.)
{
ReplyName = "Where", -- This is the name of the reply button. It can be used to reference in Exec so you can run code when this button is clicked.
ReplyText = "Where am I?", -- This is the text that will be displayed on your Reply Button.
ReplyLayer = "Layer2" -- This is what Layer the player will be sent to if the player selects this reply.
},
{
ReplyName = "Goodbye", -- This is the name of the reply button.
ReplyText = "Goodbye!", -- This is the text that will be displayed on your Reply Button.
ReplyLayer = nil -- Since the Layer is nil, the dialogue will just end as nil is not a layer and is nothing.
}
},
Exec = { -- This is where you can run code in your dialogue if you want any custom functions. (Quests, Animations, etc.)
--[[
func1 = {
Function = customFunction1, -- Set this to a function you have created. Do not leave the brackets at the end.
ExecuteContent = "_<\>continuebutton\\", -- Set to a number or the name of a Reply. If set to 1, it will execute at the first piece of content on the dialogue.
},
]]--
}
},
Layer2 = { -- This is the second layer.
DialogueContent = {"You are currently in Veletlen, and this is the Saogale Castle."}, -- This is your next piece of content if the player selects Reply1
DialogueSounds = {},
DialogueImage = npc, -- You can change the image to display here.
LayerTitle = nil, -- You can change your Dialogue Title here. Keep as nil if you don't want it to change.
Replies = {
{
ReplyName = "GiveMastery", -- This is the name of the reply button.
ReplyText = "Mastery", -- This is the text that will be displayed on your Reply Button.
ReplyLayer = "LayerMastery" -- Since the Layer is nil, the dialogue will just end as nil is not a layer and is nothing.
},
{
ReplyName = "Goodbye", -- This is the name of the reply button.
ReplyText = "Goodbye!", -- This is the text that will be displayed on your Reply Button.
ReplyLayer = nil -- Since the Layer is nil, the dialogue will just end as nil is not a layer and is nothing.
}
},
},
LayerMastery = { -- Rename LayerName to the name of your layer. It can be whatever you want as long as it isnt the same as something else!
DialogueContent = {"Sorry, you are not yet strong enough to handle the power of the flame. Come back when you have learnt the basics. (Lvl 15+) (Actually not implemented yet, WIP T-T)"},
DialogueSounds = {},
DialogueImage = npc,
LayerTitle = nil,
Replies = {
{
ReplyName = "Goodbye", -- This is the name of the reply button.
ReplyText = "Goodbye!", -- This is the text that will be displayed on your Reply Button.
ReplyLayer = nil -- Since the Layer is nil, the dialogue will just end as nil is not a layer and is nothing.
}
},
Exec = {
Special = {
Function = GiveSpecial, -- Set this to a function you have created. Do not leave the brackets at the end.
ExecuteContent = 1, -- Set to a number or the name of a Reply. If set to 1, it will execute at the first piece of content on the dialogue.
},
}
},
--[[
Use this to copy and paste a new layer if you want a clean layer.
LayerName = { -- Rename LayerName to the name of your layer. It can be whatever you want as long as it isnt the same as something else!
DialogueContent = {""},
DialogueSounds = {},
DialogueImage = "rbxassetid://000",
LayerTitle = nil,
Replies = {
},
Exec = {
}
},
]]--
},
}
return tableContent
end