How do i make a player get a gear on ReplicatedStorage via dialogue without using a currency system?

So recently, i’ve trying to code a script that makes you give a specific gear (Taken on the roblox store, but i changed the textures of the gear) without having to use a currency system. I have tried making a code via this following Roblox Wikia Article:
https://developer.roblox.com/articles/Shop-Dialogs

I have tried an attempt at making a script off this article without the leaderstats feature.
But it did not work:

  • The script is placed on the NPC’s head plus the dialogue.

  • The gear i want to give to the player is localized on the ‘‘ReplicatedStorage’’ of my place with the name of ‘‘InnovationCoffe’’

  • And most importantly, yes, it’s supposed to the player get it for free, that’s what i mean with ‘‘not using a currency system’’;

3 Likes

Are you getting any errors in the output when you select Option A, or does everything look like it’s working fine and the gear just isn’t appearing? I’m asking for a couple reasons: first, you say that the script is in the head of the NPC. I’m taking that to mean that the script’s parent is the NPC’s head and not the Dialog object. If that’s the case, dialog will reference the NPC’s head, and you should be getting an error.
Second, it looks like you’re searching for InnovationCoffe in ReplicatedStorage. Is the tool named with only one “e,” or is that a typo in the script? Again, you’re probably getting an error if that’s the case.

Also yeah, the script’s parent is on the NPC’s head, and both the dialogue.
the tool is named InnovationCoffe, i checked, there is no typos.
I got into the output, talked in with the NPC in Dialogue, no error show.
1 2
And i don’t get the gear from my toolbar.

Ah, you forgot to add a dialog choice to dialog so you can put OptionA in it.

Should look something like this

image

2 Likes

Can you format the code instead of sending a screenshot so it’s easier for us to edit the code?

Well, i’ve tried this and still nothing did work?
Here’s the formatted code. I didn’t know how to do it since it had no button to do it:

 local dialog = script.Parent

dialog.DialogChoiceSelected:connect(function(player, choice)

if choice == script.Parent.DialogChoice.OptionA then

game.ReplicatedStorage.InnovationCoffe:Clone().Parent = player.Backpack

end

end)

I’m gonna send the entire model to make this better. Just wait a moment.

1 Like

Okay, I’ve done some extra digging. It looks like the DialogChoiceSelected event only fires on the client side. That would explain why you’re not getting any errors (the event never fires to begin with).

Edit: It appears that this has happened before: Dialog.DialogChoiceSelected doesn't work in server scripts
Edit 2: I replicated your issue doing exactly what the tutorial says to do. I then moved the script to a LocalScript in StarterPlayer.StarterPlayerScripts and made some changes, and it worked:

local dialog = workspace[your NPC].Head.Dialog

dialog.DialogChoiceSelected:Connect(function(player, choice)

    -- your existing code

end)
2 Likes

That would be appreciated. I could just edit the script and send it back to you.

Here is it.
NPC.rbxm (8.1 KB)
I don’t know if you will need the gear since it’s just a gear i taken from ROBLOX with changed textures, but if you need it, let me know.
p.s: the npc avatar is not finished, so don’t mind it.

1 Like

npcDialog.rbxm (8.8 KB)

This script should work, just put dialogHanderClient in startercharacterscripts and dialogHandlerServer in serverscriptservice.
Edit:

local dialog = game.Workspace.NPCDialog.Head.Dialog

dialog.DialogChoiceSelected:connect(function(player, choice)

if choice == dialog.DialogChoice.OptionA then

game.ReplicatedStorage:WaitForChild("getTool"):FireServer()

end

end)

Copy and paste this into the client handler script forgot to add something.
Just tell me if anything doesn’t work.

Cheers!

3 Likes

It didn’t work… I made a test place so we can know why this isn’t working.

BaseplateTest.rbxl (23.9 KB)

I checked on the output and it shows up an error, and it looks like this:

21:14:53.941 - DialogChoice is not a valid member of Model
21:14:53.942 - Stack Begin
21:14:53.943 - Script ‘Workspace.thelucas7.dialogHandlerClient’, Line 3
21:14:53.943 - Stack End
21:14:56.975 - DialogChoice is not a valid member of Model
21:14:56.976 - Stack Begin
21:14:56.976 - Script ‘Workspace.thelucas7.dialogHandlerClient’, Line 3
21:14:56.977 - Stack End

Edit: forgot to replace your ClientHandler script. Still nothing worked aswell ):

Hm. It worked for me let me just send you the place.

1 Like

Heres the file just add the innovation coffe to replicated storage.
NPCDialogFile.rbxl (21.1 KB)

2 Likes

It works!
THANK YOU so much! :blush:
I’m gonna copy the local scripts and place them on the desired locations on my place.

Also, nice baseplate you got there.

It’s better to have the server do the check, as to not let an exploit see the correct choice. Ex,

-- Client
DialogChoiceSelected:Connect(function(_, ChoiceSelected)
     ChkCorrectAnswerRemote:FireServer(ChoiceSelected.Name)
end)
-- Server
ChkCorrectAnswerRemote.OnServerEvent:Connect(function(Player, ChoiceSelected)
     if ChoiceSelected == 'ChoiceA' then
          -- Code to give tool
     end
end)

Yeah, I would personally add sanity checks but this is just base code. Also that wouldn’t work as the exploiter could just do ChkCorrectAnswerRemote:FireServer(“ChoiceA”) and it’d work, but I see what you mean.