Dialogue Item Giver | Roblox Forum
Welcome to the Forums!
Join thousands of other Roblox members with a free account.
Create Forum Account

Dialogue Item Giver

  • This website was created by Roblox members to replace the official forums because Roblox shut them down! Join our community if you like to talk about Roblox!

gavington

New Member
Mar 25, 2018
12
0
1
Roblox
gavington
In one of my games I added a few npcs that will give you an item from talking to them, I made serveral adjustments to the script but nothing seems to make it work I tried searching youtube for better scripts, but they were either too outdated to work or required a money system so im to the forums. I put the the tools in lighting and the dialogue choice names are correct, Does anybody know what's wrong with this script:

script.Parent.DialogChoiceSelected:connect(function(player, choice)

if (choice == script.Parent.ChoiceNameHere) then

item = game.Lighting["ItemNameHere"]:clone()

item.Parent = player.Backpack

end

end)
 

WizardOfHills

Active Member
Jul 21, 2018
579
113
43
Roblox
WizardOfHills
The problem is that this event fires only on Client (documentation is here). For this script to be effective it must be a Script (on server).

For it to work you have to make two scripts: one LocalScript and another Script. You will also need a RemoteEvent in ReplicatedStorage with name GiveTool.
Also a typical place for templates of items is in ServerStorage or ReplicatedStorage. Lightning used to be used to keep scripts and templates really long time ago.
For the sake of this example I placed a Tool called Sword in ServerStorage.

LocalScript in StarterPlayerScripts:
Code:
event = game.ReplicatedStorage:WaitForChild("GiveTool")
dialog = workspace:WaitForChild("GiverPart"):WaitForChild("Dialog") -- of course, put here a path to your dialog
getsword = dialog:WaitForChild("GetSword")

dialog.DialogChoiceSelected:Connect(function(p, s)
    if p == game.Players.LocalPlayer and s == getsword then
        event:FireServer()
    end
end)
Script in ServerScriptService:
Code:
game.ReplicatedStorage.GiveTool.OnServerEvent:Connect(function(player)
    game.ServerStorage.Sword:Clone().Parent = player.Backpack
end)
 

gavington

New Member
Mar 25, 2018
12
0
1
Roblox
gavington
Thanks for you're help, although I don't understand what you meant by putting a path to the dialog do I need to change the name of anything in StarterPlayerScripts code?
 

WizardOfHills

Active Member
Jul 21, 2018
579
113
43
Roblox
WizardOfHills
LocalScripts do not if parented to workspace (unless they are parented to a local player's character). So you cannot just put them under Dialog inside NPC's head. Hence a typical trick with script.Parent will not work. PS. @St4 recently asked how to circumvent this in Help forum (here).

Instead LocalScripts are placed in StarterPlayerScripts and once a new player joins the game they receive a copy of such script. But one has to somehow specify where Dialog is.
 

gavington

New Member
Mar 25, 2018
12
0
1
Roblox
gavington
So I need to find a way to specify the Npc containing the dialog and name of the dialog inside the local script since it is placed in StarterPlayer for it to work, If this is the case where inside the LocalScript do I put the name of the object?
 

WizardOfHills

Active Member
Jul 21, 2018
579
113
43
Roblox
WizardOfHills
In your script Dialog is a parent of the script so script.Parent was enough to address it. Running copy of the LocalScript will be parented in game.Players.PLAYERNAME.PlayerScripts. Docs are here.

Hence one has to provide another means to find Dialog. I propose to simply write the full path and then add :WaitForChild(...). The script will run very early after the player joins the game and it may happen that not all of the game had loaded into a player's client.
 
General
Help Users
    SleepyWinq SleepyWinq: No, @Coolcatmomi