I want to make an npc that talks to you with the dialog options, and sell you a gamepass through a dialog choice. Is this possible?
you can prompt the purchase with a localscript when a certain dialog choice is hit, that is pretty easy
So I just put the script that would usually prompt a purchase when touching a brick and put it in the dialog choice?
create a function that when the dialog choice is chosen, run the gamepass purchase prompt script. it should be easy if you know how to do those two. and, yes, put the local script under the dialog choice.
I’m not exactly the best scripter, how do I make a function?
(event here):connect(functionname)
for example, in a script that would change a part name upon a touch, it would be:
function onTouch()
script.Parent.Name = "newName"
end
script.Parent.Touched:Connect(onTouch)
Well first off you would want to listen for the DialogChoiceSelected
event of Dialog
s.
In a LocalScript
, since Dialog
s don’t work on the server anymore (presumably because they were not updated to work with FE).
local dialog = -- wherever the dialog is
local client = game:GetService("Players").LocalPlayer
dialog.DialogChoiceSelected:Connect(function(player, dialog)
if player ~= client then
return
end
-- Extra code
end)
@ZurichBT that won’t work since you’re trying to connect a function that doesn’t even exist yet, move the :Connect
call to the bottom and it will work
So the I should replace dialog with the name of the dialog or with workspace.whatever?
A correct example would be:
local dialog = game.Workspace.TalkingNpc.Dialog.DialogChoice1
You’re free to edit the name as you’d like, as well as the variable name. I suggest not using workspace.Dialog for the variable name, it wouldn’t work as well and it would be very ineffective.
Thanks, I’ll try that now. Also, how do I know of a script is a localscript or serverscript?
The script name should be LocalScript and the icon is a scroll of paper with a person on it.
Also, should I put the script in the same place that the dialog is?
Yes, it should be located under the dialog choice.
Wait, under or inside the choice?
Both. Under and inside are basically the same thing.
You would put it in a place LocalScript
s can run, like PlayerScripts
, which is in StarterPlayer
.
Alright, and then what do I put where the --extra code comment is?
The code you originally had to prompt the purchase.
So, the code that originally triggered when the part was touched?
Yes, that would be what you do