Tables isn't working

Hello! So Im making dialoge for my characters but for some reason this doesnt work, and instead I get a syntax error

Script

DialogeModule

local DialogModule = {{
	["Null"] = {
		[1] = "Hello! Im Null! What brings you Here?",
		[2] = "Oh Your that type of Life!",
		[3] = "A Human... I dont see much come here!",
		[4] = "Its Surprising, I thought they were extinct!",
		[5] = "I dont know much about this place eathier, I still call it home though!",
		[6] = "My home is also my buddy :), They can tranform themselfs into anything they like!",
		[7] = "I dont know much about this place yet, but Its a infinite path waiting for its holder, How Delightful!",
		[8] = "Anyways, They call me NULL For short, I still am figuring out what I am myself!",
		[9] = "Im still just curious how you got here! Hmmm... A new enviourment to explore!",
		[10] = "Good Luck on your Journey, Player!"
		["Buckles"] = {
			[1] = "Howdy Bucko!",
			[2] = "What are you doin down here in my home?",
			[3] = "Anyway, This is my factory, The Oof Box Factory"
			[4] = "I found it inside of this very area with Checkers around dem walls..."
			[5] = "I dont remember how I got here but I was inside of the upzone with my friends"
			[6] = "When I went to sleep and then when I got here I just woke up"
			[7] = "WHAT IN TARNATION!"
			[8] = "Thats what I yelled as soon as sunrise came..."
			[9] = "I never really new this place but I latter claimed it as mine when I saw it"
			[10] = "I dont know weer that portal goes to on this very day..."
			[11] = "But one day I will make it back up and leave this area"
			[12] = "Anyway, Goodbye Bucko."
		}
	}
}

return DialogModule

You forgot a comma on line 12. And on lines 16 to 25.

2 Likes

Like this?

local DialogModule = {
	["Null"] = {
		[1] = "Hello! Im Null! What brings you Here?",
		[2] = "Oh Your that type of Life!",
		[3] = "A Human... I dont see much come here!",
		[4] = "Its Surprising, I thought they were extinct!",
		[5] = "I dont know much about this place eathier, I still call it home though!",
		[6] = "My home is also my buddy :), They can tranform themselfs into anything they like!",
		[7] = "I dont know much about this place yet, but Its a infinite path waiting for its holder, How Delightful!",
		[8] = "Anyways, They call me NULL For short, I still am figuring out what I am myself!",
		[9] = "Im still just curious how you got here! Hmmm... A new enviourment to explore!",
		[10] = "Good Luck on your Journey, Player!",
		["Buckles"] = {
			[1] = "Howdy Bucko!",
			[2] = "What are you doin down here in my home?",
			[3] = "Anyway, This is my factory, The Oof Box Factory",
			[4] = "I found it inside of this very area with Checkers around dem walls...",
			[5] = "I dont remember how I got here but I was inside of the upzone with my friends",
			[6] = "When I went to sleep and then when I got here I just woke up",
			[7] = "WHAT IN TARNATION!",
			[8] = "Thats what I yelled as soon as sunrise came...",
			[9] = "I never really new this place but I latter claimed it as mine when I saw it",
			[10] = "I dont know weer that portal goes to on this very day...",
			[11] = "But one day I will make it back up and leave this area",
			[12] = "Anyway, Goodbye Bucko."
		}
	}
}

return DialogModule

Yes, it should work. Are there any errors?

1 Like

Yes their is, Its an error that was caused by the Main Dialouge Handler

Error

  19:22:07.386  Stack Begin  -  Studio
  19:22:07.386  Script 'ServerScriptService.kxghtisms tag :)', Line 5  -  Studio - kxghtisms tag :):5
  19:22:07.386  Stack End  -  Studio
  19:22:14.697  Players.NubblyFry.PlayerGui.Status.TextLabel.LocalScript:12: attempt to index nil with 'GetPropertyChangedSignal'  -  Client - LocalScript:12
  19:22:14.697  Stack Begin  -  Studio
  19:22:14.697  Script 'Players.NubblyFry.PlayerGui.Status.TextLabel.LocalScript', Line 12  -  Studio - LocalScript:12
  19:22:14.697  Stack End  -  Studio
  19:22:16.571  Reward is not a valid member of Folder "Players.NubblyFry.leaderstats"  -  Client - check:3
  19:22:16.571  Stack Begin  -  Studio
  19:22:16.571  Script 'Players.NubblyFry.PlayerGui.DailyReward.Frame.check', Line 3  -  Studio - check:3
  19:22:16.571  Stack End  -  Studio
  19:22:18.575  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1900786800  -  Studio
  19:22:18.746  0.5, 0.5  -  Client
  19:22:19.025  0.5, 0.5  -  Server
  19:22:19.990  Players.NubblyFry.PlayerGui.Dialog.LocalScript:32: attempt to index nil with number  -  Client - LocalScript:32
  19:22:19.991  Stack Begin  -  Studio
  19:22:19.991  Script 'Players.NubblyFry.PlayerGui.Dialog.LocalScript', Line 32 - function OnDialog  -  Studio - LocalScript:32
  19:22:19.992  Script 'Players.NubblyFry.PlayerGui.Dialog.LocalScript', Line 93  -  Studio - LocalScript:93
  19:22:19.992  Stack End  -  Studio
  19:22:21.039  Players.NubblyFry.PlayerGui.Dialog.LocalScript:32: attempt to index nil with number  -  Client - LocalScript:32
  19:22:21.040  Stack Begin  -  Studio
  19:22:21.040  Script 'Players.NubblyFry.PlayerGui.Dialog.LocalScript', Line 32 - function OnDialog  -  Studio - LocalScript:32
  19:22:21.040  Script 'Players.NubblyFry.PlayerGui.Dialog.LocalScript', Line 59  -  Studio - LocalScript:59
  19:22:21.041  Stack End  -  Studio

Dialouge Handler

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local DialogModule = require(ReplicatedStorage.DialogModule)
local p = game.Players.LocalPlayer
local NPCs = workspace.NPCs
local DialogFrame = script.Parent.DialogFrame
local InputButton = DialogFrame.Input
local NPCName = DialogFrame.NPCName

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, TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {
			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, TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {
				Position = UDim2.new(0, 0, 1, 0)
			})
			DialogTween = Tween
			DialogTween:Play()
			
			DialogIndex = 1
			OnDialog(Dialog, DialogIndex, ProximityPrompt)
		end)
	end
end

Screenshot 2021-06-15 192457

Are those supposed to be separate dialogue nodes? You have them joined together for some reason so the Buckles table is part of the Null table. That’s probably what’s causing errors in your code. Remember to close up the last element of Null’s dialogue with a closing brace so that Buckles’ dialogue lines don’t appear in Null’s table.

You closed the table at the wrong place, and you need a comma to separate them.

Fixed:

local DialogModule = {{
	["Null"] = {
		[1] = "Hello! Im Null! What brings you Here?",
		[2] = "Oh Your that type of Life!",
		[3] = "A Human... I dont see much come here!",
		[4] = "Its Surprising, I thought they were extinct!",
		[5] = "I dont know much about this place eathier, I still call it home though!",
		[6] = "My home is also my buddy :), They can tranform themselfs into anything they like!",
		[7] = "I dont know much about this place yet, but Its a infinite path waiting for its holder, How Delightful!",
		[8] = "Anyways, They call me NULL For short, I still am figuring out what I am myself!",
		[9] = "Im still just curious how you got here! Hmmm... A new enviourment to explore!",
		[10] = "Good Luck on your Journey, Player!"
	},
	["Buckles"] = {
		[1] = "Howdy Bucko!",
		[2] = "What are you doin down here in my home?",
		[3] = "Anyway, This is my factory, The Oof Box Factory"
		[4] = "I found it inside of this very area with Checkers around dem walls..."
		[5] = "I dont remember how I got here but I was inside of the upzone with my friends"
		[6] = "When I went to sleep and then when I got here I just woke up"
		[7] = "WHAT IN TARNATION!"
		[8] = "Thats what I yelled as soon as sunrise came..."
		[9] = "I never really new this place but I latter claimed it as mine when I saw it"
		[10] = "I dont know weer that portal goes to on this very day..."
		[11] = "But one day I will make it back up and leave this area"
		[12] = "Anyway, Goodbye Bucko."
	},
}

return DialogModule
2 Likes