What do you want to achieve?
When the player clicks on the ‘Soda’ choice textbox, the item (within ReplicatedStorage) will be cloned and the player will be given the cloned item.
What is the issue?
When the player clicks the choice GUI button, they’re not being given the item.
What solutions have you tried so far?
I’ve tried re-writing that portion of the script since everything else works; however, it still isn’t working. I’m using a module script & local script with the give item function in the local script. Within my local script, I’ve marked where I believe the issue(s) is/are with the following statement…
— HERE IS WHERE IS BELIEVE MY ISSUE IS!!!
Replicated Storage (Screenshot)
Local Script (Client)
Workspace Screenshot
Script
local tweenService = game:GetService("TweenService")
local replicated = game:GetService("ReplicatedStorage")
local event = replicated:WaitForChild("TalkEvent")
local camera = workspace.CurrentCamera
local main = script.Parent.Main
local choicesFrame = main.ChoicesFrame
local nameLabel = main.NameFrame.Label
local dialogLabel = main.DialogFrame.Label
local choiceTemplate = script.ChoiceTemplate
local currentNpc = nil
local storedChoices = {}
local function typeWrite(text, label)
label.Text = ""
for i, v in text:split("") do
label.Text = label.Text .. v
task.wait(0.05)
end
end
local function endDialog(info)
for i, child in pairs(choicesFrame:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
end
end
typeWrite(info.LeaveMessage, dialogLabel)
task.wait(0.5)
currentNpc.HumanoidRootPart.ProximityPrompt.Enabled = true
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = game.Players.LocalPlayer.Character
main:TweenPosition(UDim2.new(0,0,1,0))
task.wait(1)
main.Visible = false
nameLabel.Text = ""
dialogLabel.Text = ""
storedChoices = {}
currentNpc = nil
end
local function nextDialog(info, lastChoice)
for i, child in pairs(choicesFrame:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
end
end
local dialog
if lastChoice then
if lastChoice.Next then
dialog = info.Dialog[lastChoice.Next]
local humanoid = game.Workspace.NPCs.ImportedRthroRigTest.Humanoid --change the path if ur dummy is named smth else
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=12027999310"
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
else
local humanoid = game.Workspace.NPCs.ImportedRthroRigTest.Humanoid --change the path if ur dummy is named smth else
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=12028180947"
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
endDialog(info)
end
local humanoid = game.Workspace.NPCs.ImportedRthroRigTest.Humanoid --change the path if ur dummy is named smth else
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=12026696252"
local animationTrack = humanoid:LoadAnimation(animation)
if dialog.Text == "Coming right up! Anything else I can do for you?" then
animationTrack:Play()
end
else
dialog = info.Dialog[1]
local humanoid = game.Workspace.NPCs.ImportedRthroRigTest.Humanoid --change the path if ur dummy is named smth else
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=12028180947"
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
end
if not dialog then return end
typeWrite(dialog.Text, dialogLabel)
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
-- HERE IS WHERE IS BELIEVE MY ISSUE IS!!!
clone.MouseButton1Click:Connect(function()
storedChoices[i] = nil
if clone.Label.Text == "Soda" then
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
nextDialog(info, choice)
end)
end
for i, choice in 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
-- HERE IS WHERE IS BELIEVE MY ISSUE IS!!!
clone.MouseButton1Click:Connect(function()
storedChoices[i] = nil
if clone.Label.Text == "Soda" then
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
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()
local humanoid = game.Workspace.NPCs.ImportedRthroRigTest.Humanoid --change the path if ur dummy is named smth else
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=12028180947"
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
endDialog(info)
end)
else
task.wait(1)
if dialog.Next then
nextDialog(info, dialog)
else
local humanoid = game.Workspace.NPCs.ImportedRthroRigTest.Humanoid --change the path if ur dummy is named smth else
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=12028180947"
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
endDialog(info)
end
end
end
event.OnClientEvent:Connect(function(npc, info, cameraCF)
if currentNpc == nil and npc then
currentNpc = npc
nameLabel.Text = npc.Name
dialogLabel.Text = ""
storedChoices = {}
for i, child in pairs(choicesFrame:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
end
end
if cameraCF then
npc.HumanoidRootPart.ProximityPrompt.Enabled = false
camera.CameraType = Enum.CameraType.Scriptable
tweenService:Create(workspace.CurrentCamera, TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut), {CFrame = cameraCF}):Play()
end
main.Position = UDim2.new(0,0,1,0)
main.Visible = true
main:TweenPosition(UDim2.new(0,0,0,0))
task.wait(1)
nextDialog(info, nil)
end
end)
Module Script (Info)
I’ve included this information just incase it’s needed and provides any additional useful information!
Workspace Screenshot
Script
local Info = {}
Info.LeaveMessage = "See you around, darling!"
Info.CameraDistance = 3
Info.Dialog = {
[1] = {
Text = "Hey there! What can I do for you?";
Choices = {
[1] = { Text = "Nothing really..."; Next = 2};
[2] = { Text = "I'd like to purchase something."; Next = 3; Follow = true };
[3] = { Text = "I'd like to chat."; Next = 4 };
}
};
[2] = { Text = "No worries, thanks for saying hi!"; };
[3] = {
Text = "Great! What can I get for you?";
Choices = {
[1] = { Text = "A drink."; Next = 5 };
[2] = { Text = "An item, please."; Next = 6};
[4] = { Text = "I just wanna chat."; Next = 4};
}
};
[4] = {
Text = "You're too sweet — I should probably get back to work though ... catch me after my shift!"; };
[5] = {
Text = "Sure, what'd you like to drink?";
Choices = {
[1] = { Text = "Soda."; Next = 6};
[2] = { Text = "Water."; Next = 6};
[3] = { Text = "A fancy drink."; Next = 6};
[4] = { Text = "A plain drink."; Next = 6};
[5] = { Text = "Surprise me!"; Next = 6};
}
};
[6] = {
Text = "Coming right up! Anything else I can do for you?";
Choices = {
[1] = { Text = "Nothing really..."; Next = 2};
[2] = { Text = "I'd like to chat."; Next = 4};
[3] = { Text = "I'd like to purchase something."; Next = 3};
}
};
[7] = {
Text = "Sure, which item would you like?";
Choices = {
[1] = { Text = "---"; Next = 8};
[2] = { Text = "---"; Next = 8};
[3] = { Text = "Actually, can I order a drink?"; Next = 5};
[4] = { Text = "---"; Next = 8};
}
};
[8] = {
Text = "Here you go! Anything else I can do for you?";
Choices = {
[1] = { Text = "Nothing really..."; Next = 2};
[2] = { Text = "I'd like to chat."; Next = 4};
[3] = { Text = "I'd like to purchase something."; Next = 3};
}
};
}
return Info
Thank you so much for your help — it’s sincerely appreciated Also, let me know if there is anything else I can provide to you to help me figure out my problem!
Can you print something where the “if clone.Label.Text == “Soda” then” so I know its being activated and print something inside to see if its getting past the if statement
for i, choice in 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 clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
nextDialog(info, choice)
end)
end
print(if dialog.Choices then #dialog.Choices else "No dialog choices", #storedChoices)
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 clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
nextDialog(info, choice)
print("Test")
end)
end
There are no stored choices (which is right) & it also shows the correct # of choices. The video will show the order of each function to get a better idea (it’s finished uploading!)
Not sure if I’m doing this right… it’s not printing the clone.Label.Text in the output.
Script:
print(if dialog.Choices then #dialog.Choices else "No dialog choices", #storedChoices)
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
print(if clone.Label.Text then "..." else "No clone.Label.Text")
clone.MouseButton1Click:Connect(function()
storedChoices[i] = nil
if clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
nextDialog(info, choice)
print("Test")
end)
end
I see! The output works now but it just prints as ‘’…’’ (I uploaded a video to show you) (it’s finished uploading)
Here’s the revised script:
typeWrite(dialog.Text, dialogLabel)
print(if dialog.Choices then #dialog.Choices else "No dialog choices", #storedChoices)
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
print(if clone.Label.Text then "..." else "No clone.Label.Text")
clone.MouseButton1Click:Connect(function()
print(if clone.Label.Text then "..." else "No clone.Label.Text")
storedChoices[i] = nil
if clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
nextDialog(info, choice)
print("Test")
end)
end
for i, choice in dialog.Choices do
local clone = choiceTemplate:Clone()
clone.Parent = choicesFrame
clone.Name = choice.Text
clone.Label.Text = choice.Text
print(if clone.Label.Text then "..." else "No clone.Label.Text")
if choice.Follow == true then
storedChoices[i] = choice
end
clone.MouseButton1Click:Connect(function()
print(if clone.Label.Text then "..." else "No clone.Label.Text")
storedChoices[i] = nil
if clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
nextDialog(info, choice)
print("Test")
end)
end
EDIT: I just realized that the output wouldn’t be as useful so I did this instead!
typeWrite(dialog.Text, dialogLabel)
print(if dialog.Choices then #dialog.Choices else "No dialog choices", #storedChoices)
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
print(if clone.Label.Text then "1" else "No clone.Label.Text")
clone.MouseButton1Click:Connect(function()
print(if clone.Label.Text then "2" else "No clone.Label.Text")
storedChoices[i] = nil
--added
if clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
--added
nextDialog(info, choice)
print("Test")
end)
end
for i, choice in dialog.Choices do
local clone = choiceTemplate:Clone()
clone.Parent = choicesFrame
clone.Name = choice.Text
clone.Label.Text = choice.Text
print(if clone.Label.Text then "3" else "No clone.Label.Text")
if choice.Follow == true then
storedChoices[i] = choice
end
clone.MouseButton1Click:Connect(function()
print(if clone.Label.Text then "4" else "No clone.Label.Text")
storedChoices[i] = nil
--added
if clone.Label.Text == "Soda" then
print("SODA GIVEN")
local player = script.Parent.Parent.Parent
local tool = game.ReplicatedStorage.Soda:Clone()
tool.Parent = player.Backpack
end
--added
nextDialog(info, choice)
print("Test")
end)
end
It appears that the name of the Text is “Soda.” (with a period), and you’re comparing it against “Soda”, without a period. Change clone.Label.Text == "Soda" with clone.Label.Text == "Soda."