Hey, new guy to scripting and the devforums here. Currently having two issues when it comes to this dialogue script I’ve created.
Issue one is the game fires the script when it’s not supposed to.
for i, v in pairs(game.Workspace.Actors:GetChildren()) do
if v:FindFirstChild("ProximityPrompt") then
if v.CanSpeak.Value == true then
v.CanSpeak.Value = false
v.ProximityPrompt.Triggered:Connect(function(player)
local diainfo = require(v.DialogueInfo)
local scene = "placeholder" --get the module for day/scene tracker and send to client
TalkStart:FireClient(player, diainfo, scene)
end)
end
end
end
Here, I have a folder set up to put NPCs in. The server script checks the folder for anything with a ProximityPrompt and checks if “CanSpeak” is true or false. If it is true, the script runs and sets the value to false. If it’s false, it should not run. If I set the value to false in the Studio editor before running the game, the script doesn’t fire. But for some reason, if I do it this way, the script runs, sets the value to false, and then doesn’t prevent the script from running again.
The game can very clearly see if CanSpeak is true or false because it can or can’t run depending on what its set to before I run the game, so I have no idea what could be causing this issue.
Issue two is that I don’t know how to end dialogue.
game.ReplicatedStorage.TalkStart.OnClientEvent:Connect(function(diainfo, scene) --Receives the RemoteEvent containing the npc name, dialogue info, and scene
--Functions setup
--TODO: Require the module script for tracking the day and scene and display dialogue accordingly
local function typewriter(text, label)
speaking = true
print("typewrite start")
label.Text = ""
for i = 1, #text do
label.Text = string.sub(text, 1, i)
repstorage.AudioFolder.SFX.Tick:Play()
wait(0.01)
end
speaking = false
end
local function nextDialogue(text, scene)
local currentdialogue = 1
dialogueframe.TextLabel.Text = ""
nameframe.TextLabel.Text = text.Dialogue[currentdialogue].Name
typewriter(diainfo.Dialogue[currentdialogue].diaText, dialogueframe.TextLabel)
print("Dialogue start")
repstorage.AudioFolder.SFX.MenuClick:Play()
uis.InputEnded:Connect(function(key, processed)
if key.UserInputType == Enum.UserInputType.MouseButton1 or key.KeyCode.EnumType == Enum.KeyCode.Space then
if speaking == false then
currentdialogue = currentdialogue + 1
nameframe.TextLabel.Text = text.Dialogue[currentdialogue].Name
print(currentdialogue)
--dialogueframe.TextLabel.Text = text.Dialogue[currentdialogue].diaText
typewriter(diainfo.Dialogue[currentdialogue].diaText, dialogueframe.TextLabel)
end
end
end)
end
--The actual script start
script.Parent.Enabled = true
dialogueframe.TextLabel.Text = ""
nextDialogue(diainfo, scene)
end)
This script is a little rough and unfinished but it works perfectly fine. The server script from earlier basically looks into the NPCs folder, finds a module script containing dialogue information, then sends it to this local script to be shown to the player. Here is an example of what the module script looks like.
DialogueInfo.Dialogue = {
[1] = {
Name = "TemplateR6";
Avatar = {avatar.Hod, avatar.Yesod};
diaText = "testing dialogue"
};
[2] = {
Name = "Name change test";
Avatar = {avatar.Hod, avatar.Yesod};
diaText = "testing dialogue 2"
};
[3] = {
Name = "TemplateR6";
Avatar = {avatar.Yesod, avatar.Hod};
diaText = "testing dialogue 3"
};
[4] = {
Name = "TemplateR6";
Avatar = {avatar.Hod, avatar.Yesod};
diaText = "Trigger test";
Trigger = DialogueInfo.Triggers.brickColorRandomizer
}
}
An example of the script in action.
robloxapp-20240906-1848413.wmv (255.0 KB)
The current issue is I have no idea how to end the dialogue. Clicking through the dialogue works up until there’s no more dialogue left. At which point if I keep clicking, I’ll get an error stating something like “Players.MoberisFGC.PlayerGui.DialogueScreen.DialogueClient:58: attempt to index nil with ‘Name’”. Any and all help or advice is appreciated. Thanks.