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