i need help i wan to add a way to execute function with dialogue choices
so i have a script from dialogue and i have a thing called action
local Info = {}
Info.LeaveMessage = "Goodbye, I'll see you around"
Info.CameraDistance = 3
Info.Dialog = {
[1] = {
Text = "Hello, how are you?";
Choices = {
[1] = { Text = "Bad"; Action = function(player)
print("Bad choice selected")
player.Character.Humanoid.Health = player.Character.Humanoid.Health - 10
end; },
[2] = { Text = "Good, how are you?"; Next = 3; },
[3] = { Text = "I'm alright"; Next = 4; },
}
};
[2] = { Text = "I'm sorry to hear that"; };
[3] = {
Text = "I'm great, thanks for asking";
Choices = {
[1] = { Text = "What's your name?"; Next = 5; Follow = true; },
[2] = { Text = "Where are you from?"; Next = 6; Follow = true; },
[4] = { Text = "Nice weather, right?"; Next = 7; Follow = true; },
}
};
[4] = { Text = "I feel the same way"; };
[5] = { Text = "My name is NPC 1"; };
[6] = { Text = "I'm from the Baseplate"; };
[7] = { Text = "Mmmmmmh definitely"; };
}
return Info
then i have a script that handles all the dialogue i added a if choices.Action then it fires that action but its acting as if the action is not there
if dialog.Choices and (#dialog.Choices > 0 or #storedChoices > 0) then
for i, choice in pairs(storedChoices) do
local clone = choiceTemplate:Clone()
clone.Parent = choicesFrame
clone.Name = choice.Text
clone.Label.Text = choice.Text
clone.MouseButton1Click:Connect(function()
storedChoices[i] = nil
if choice.Action then
print("Executing stored choice action for: " .. choice.Text)
choice.Action(game.Players.LocalPlayer)
else
print("No action for stored choice: " .. choice.Text)
end
nextDialog(info, choice)
end)
end
for i, choice in pairs(dialog.Choices) do
local clone = choiceTemplate: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
if choice.Action then
print("Executing action for choice: " .. choice.Text)
choice.Action(game.Players.LocalPlayer)
else
print("No action for choice: " .. choice.Text)
end
nextDialog(info, choice)
end)
end
local leave = choiceTemplate:Clone()
leave.Parent = choicesFrame
leave.Name = "Leave"
leave.BackgroundColor3 = Color3.fromRGB(77, 35, 36)
leave.Label.Text = "I have to go"
leave.MouseButton1Click:Connect(function()
endDialog(info)
end)
else