Item isn't being given to the player?

  1. 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.

  2. What is the issue?
    When the player clicks the choice GUI button, they’re not being given the item.

  3. 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)

Screen Shot 2023-01-03 at 8.51.47 PM

Local Script (Client)

Workspace Screenshot

Screen Shot 2023-01-03 at 8.52.49 PM
Screen Shot 2023-01-03 at 8.51.59 PM

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! :slight_smile:

Workspace Screenshot

Screen Shot 2023-01-03 at 8.53.57 PM

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 :heart: 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

1 Like

Are there any errors generated on the output? If so, can you tell us the error?

1 Like

Thank you for your reply, there are no output errors… sadly (as it’d probably make it easier to find the issue)!

1 Like

Like this?

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

Yes, this will tell me if it gets past the if statement

1 Like

The “SODA GIVEN” did not print.

So either,

  1. The Mouse Button Function isnt being called or the if statement is false

print a message out the if statement

Before the line:

if dialog.Choices and (#dialog.Choices > 0 or #storedChoices > 0) then

print the number of dialog.Choices and storedChoices. See if they are more than 0.

print(if dialog.Choices then #dialog.Choices else "No dialog choices", #storedChoices)
1 Like

I’ve uploaded a screen recorded video of the output here (I hope this can bu useful): output vid on Vimeo

EDIT: It might take a while to optimize the video. Basically, the print works correctly. Here’s what it looks like:

 21:24:42.791  3 0  -  Client - Client:112
  21:24:47.142  4 0  -  Client - Client:112
  21:24:47.144  Test  -  Client - Client:158
  21:24:52.227  5 0  -  Client - Client:112
  21:24:52.228  Test  -  Client - Client:158
  21:24:57.194  3 0  -  Client - Client:112
  21:24:57.195  Test  -  Client - Client:158

Here’s the 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

			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

Unfortunately, the Vimeo link is unavailable for me. You can simply say what the output was.

1 Like

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!)

Can you print the clone.Label.Text? The choice may be different?

1 Like

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

There are two loops, right? There’s one for dialog.Choices? Try there. The print function should be under the MouseButton1Click too.

1 Like

I see! The output works now but it just prints as ‘’…’’ (I uploaded a video to show you) :slight_smile: (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!

Output:

 22:07:06.597  3 0  -  Client - Client:112
  22:07:06.598   ▶ 3 (x3)  -  Client - Client:144
  22:07:14.610  4  -  Client - Client:150
  22:07:16.546  4 0  -  Client - Client:112
  22:07:16.546   ▶ 3 (x3)  -  Client - Client:144
  22:07:16.548  Test  -  Client - Client:161
  22:07:18.809  4  -  Client - Client:150
  22:07:20.764  5 0  -  Client - Client:112
  22:07:20.765   ▶ 3 (x5)  -  Client - Client:144
  22:07:20.767  Test  -  Client - Client:161
  22:07:23.001  4  -  Client - Client:150
  22:07:26.279  3 0  -  Client - Client:112
  22:07:26.279   ▶ 3 (x3)  -  Client - Client:144
  22:07:26.281  Test  -  Client - Client:161

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 "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

I think you should use print(clone.Label.Text) instead, as we may be able to see if the text of the Label actually matches up with “Soda”.

1 Like

Alright, I’ll change that in the script!

EDIT: Alright, here’s the output (after the “Great, What can I get for you?” prompt)

22:10:21.494  A drink.  -  Client - Client:150 --this appears after the click
  22:10:23.499  5 0  -  Client - Client:112
  22:10:23.500  Soda.  -  Client - Client:144 --choice
  22:10:23.500  Water.  -  Client - Client:144 --choice
  22:10:23.501  A fancy drink.  -  Client - Client:144 --choice
  22:10:23.501  A plain drink.  -  Client - Client:144 --choice
  22:10:23.501  Surprise me!  -  Client - Client:144 --choice
  22:10:23.502  Test  -  Client - Client:161
  22:10:26.377  Soda.  -  Client - Client:150 --this appears after the click
  22:10:29.481  3 0  -  Client - Client:112
  22:10:29.482  Nothing really...  -  Client - Client:144 --choice
  22:10:29.482  I'd like to chat.  -  Client - Client:144 --choice
  22:10:29.483  I'd like to purchase something.  -  Client - Client:144 --choice
  22:10:29.483  Test  -  Client - Client:161
1 Like

Alright, it was a simple mistake:

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."

2 Likes

Oh gee, silly me … :sweat_smile: Thank you for all of your help and for taking the time to teach me so many things!!! :heart: I’ve really learned a lot from your help!

1 Like