Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a DialogChoice that gives you a item deciding on what you choose?

Here's my code:

local tool = game.Lighting["Regular Island Coffee"]
local dialog = script.Parent.Parent.Coffee

dialog.DialogChoiceSelected:connect(function(player, choice)
	if (choice == script.Parent.coffee) then
	if player.Backpack.tool == nil then
			tool:Clone().Parent = player.Backpack
		end
	end
	end)

If anyone would tell me how to fix this script, much would be appreciated.

If you click "Coffee" in the DialogChoice, it would give you a "Regular Island Coffee" tool.

If the Coffee is not in the backpack, put it in the backpack and clones. If the Coffee is in the backpack, it does nothing.

I was watching a Youtube Tutorial on this, I followed this exactly with a few changes. Here's the link: https://www.youtube.com/watch?v=QcoL43S4m5w

1 answer

Keep in mind, the players backpack is local to the player. Meaning you would have to use remote events to fetch the players backpack.

Heres an example script:

Server script:

local tool = game.Lighting["Regular Island Coffee"]
local dialog = script.Parent.Parent.Coffee
local event1 = game.Lighting.Fetch --Replicated storage works too
local event2 = game.Lighting.Give
	 
	dialog.DialogChoiceSelected:connect(function(player, choice)
	    if (choice == script.Parent.coffee) then
		event1:FireClient(player)
	  	event.1OnServerEvent:Connect(function(i)
			
			if i == true then
				
				event2:FireClient(player)
				
			end
			
		end)
 		end)

Local script:

local event1 = game.Lighting.Fetch
local event2 = game.Lighting.Give

event1.OnClientEvent:Connect(function()
	
	local backpack = game.Players.LocalPlayer.Backpack
	for i,v in pairs(backpack:GetChildren()) do
	
	if v.Name == "Regular Island Coffee" then
	
		local found = true
		
	end
	
	end
	
	if found == true then --If we found the item, tell the server. We don't use an else because we don't want to tell the server they don't have it because we haven't fully checked the backpack.
		
		event1:FireServer(false)
		
	else
		
		event1:FireServer(true)
		
	end
	
end)

event2.OnClientEvent:Connect(function()
	
	local clone = game.Lighting["Regular Island Coffee"]
	clone.Parent = game.Players.LocalPlayer.Backpack
	
end

Sorry this took so long to write. I've been answering a lot of questions and I'm quite tired.

5 comments

0

Thanks so much!

0

Oops, problem! I followed all the steps in your Script (not LocalScript). Is there any errors? Also, I fixed that one place.

0

Did you receive any errors or did it just break? (Errors are listed in the output tab if you didn't know)

0

Just to confirm, make sure your using RemoteEvent's not BindableEvent's. (Similar name, completely different purposes)

0

Uh oh! I found a major error in the LocalScript, lemme fix it.

This discussion is preserved as it was. New answers, comments, and votes are closed.