Hello devlopers! I have having problems linking the module scripts to this local script in starter GUI which function a dialog system. I want it to check if player has a certain tool, it will play Part 2 of the module and if player has nothing, it will play the first part (which is the default part when player first started talking to the NPC.
Module:
local DialogModule = {
["Scarabela"] = {
["Part1"] = {
[1] = "NO",
};
["Part2"] = {
[1] = "YAY",
}
}
}
return DialogModule
Local inside the dialog:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local DialogModule = require(ReplicatedStorage.DialogModule)
local p = Players.LocalPlayer
local NPCs = workspace.NPCs
local DialogFrame = script.Parent.DialogFrame
local InputButton = DialogFrame.Input
local NPCName = DialogFrame.NPCName
local DIALOG_TWEENINFO = TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
local dialogOpen = false
local dialogTween = nil
local dialogIndex = 0
local gradualTextInProgress = false
local function gradualText(text)
if gradualTextInProgress then
return
end
local length = string.len(text)
for i = 1, length, 1 do
gradualTextInProgress = true
DialogFrame.DialogText.Text = string.sub(text, 1, i)
wait()
end
gradualTextInProgress = false
end
local function onDialog(dialog, index, proximityPrompt)
if dialog[index] then
gradualText(dialog[index])
else
if dialogTween then
dialogTween:Cancel()
dialogTween = nil
end
local tween = TweenService:Create(DialogFrame, DIALOG_TWEENINFO, {
Position = UDim2.new(0, 0, 2, 0)
})
dialogTween = tween
dialogTween:Play()
proximityPrompt.Enabled = true
dialogOpen = false
dialogIndex = 0
p.Character.HumanoidRootPart.Anchored = false
end
end
InputButton.MouseButton1Click:Connect(function()
if gradualTextInProgress then
return
end
local dialog = DialogModule[NPCName.Value]
dialogIndex += 1
onDialog(dialog, dialogIndex, NPCs[NPCName.Value].HumanoidRootPart.ProximityPrompt)
end)
for _, NPC in pairs(NPCs:GetChildren()) do
local humanoidRootPart = NPC:FindFirstChild("HumanoidRootPart")
local proximityPrompt = humanoidRootPart:FindFirstChild("ProximityPrompt")
if humanoidRootPart and proximityPrompt then
proximityPrompt.ObjectText = NPC.Name
proximityPrompt.ActionText = "Chat with " .. NPC.Name
local dialog = DialogModule[NPC.Name]
proximityPrompt.Triggered:Connect(function()
if dialogOpen then
return
end
dialogOpen = true
proximityPrompt.Enabled = false
NPCName.Value = NPC.Name
p.Character.HumanoidRootPart.Anchored = true
if dialogTween then
dialogTween:Cancel()
dialogTween = nil
end
local tween = TweenService:Create(DialogFrame, DIALOG_TWEENINFO, {
Position = UDim2.new(0, 0, 1, 0)
})
dialogTween = tween
dialogTween:Play()
dialogIndex = 1
onDialog(dialog, dialogIndex, proximityPrompt)
end)
end
end
Thank you so much for your help!