I recently made a script and watched a lot of tutorials about dialog givers, but they seem that they need FE disabled and something about remote events which I am absolutely unfamiliar with.
local rs = game.GetService('ReplicatedStorage')
local Toaster = rs:WaitForChild('Toast')
script.Parent.DialogChoiceSelected:Connect(function(player, Dialog)
if Dialog.Name == 'Dialog' then
if player.Backpack:FindFirstChild('Toast') == nil then
Toaster:Clone().Parent = player.Backpack
end
end
end)
The replies at Dev forum also don’t work, including Dev Articles. They “had” a shop dialogs article, but it was removed or something. So I am wondering, should i create shops without dialogs now? Or just going and creating remote function script?
According to developer documentation the event is client-side only and wont fire on the server, therefore attempting to listen to it from a Script does not work. Instead create a LocalScript which fires a remote on DialogChoiceSelected that gets picked up from a Script which parents the tool:
--Script inside ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Toaster = ReplicatedStorage:WaitForChild("Toast")
local Remote = Instance.new("RemoteEvent", ReplicatedStorage)
Remote.Name = "ChatRemote"
function HasTool(player, name)
local case1 = (player.Backpack and player.Backpack:FindFirstChild(name))
local case2 = (player.Character and player.Character:FindFirstChild(name))
--if the tool is found inside their character or backpack, they have it
return (case1 or case2)
end
Remote.OnServerEvent:Connect(function(player)
if not HasTool(player, Toaster.Name) then
Toaster:Clone().Parent = player.Backpack
end
end)
--LocalScript inside StarterCharacterScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--path to dialog
local Dialog = workspace.Dummy.Head.Dialog
local Toaster = ReplicatedStorage:WaitForChild("Toast")
local Remote = ReplicatedStorage:WaitForChild("ChatRemote")
Dialog.DialogChoiceSelected:Connect(function(player, Dialog)
if Dialog.Name == "Dialog" then
Remote:FireServer()
end
end)
local tools = {
["Toast"] = Toaster,
["Tool2"] = Tool2Path,
["Tool3"] = Tool3Path
--etc.
}
Remote.OnServerEvent:Connect(function(player, toolname)
local tool = tools[toolname]
if tool and not HasTool(player, toolname) then
tool:Clone().Parent = player.Backpack
end
end)
I am also trying to do the same thing and have different tools for different dialog choices. I tried implementing the second script you posted but it didn’t work. I’m not sure how the game is supposed to know what dialog choice is related to what tool, so I added a different LocalScript for each tool with their respective dialog choice paths and tool paths but it still didn’t work. This is what I did:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Toaster = ReplicatedStorage:WaitForChild("Toast")
local Remote = Instance.new("RemoteEvent", ReplicatedStorage)
Remote.Name = "ChatRemote"
local tools = {
["Toast2"] = ReplicatedStorage:WaitForChild("Toaster2"),
["Toast"] = Toaster
}
Remote.OnServerEvent:Connect(function(player, toolname)
local tool = tools[toolname]
if tool(player, toolname) then
tool:Clone().Parent = player.Backpack
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--path to dialog
local Dialog = workspace.Dummy.Head.Dialog
local Toaster2 = ReplicatedStorage:WaitForChild("Toast2")
local Remote = ReplicatedStorage:WaitForChild("ChatRemote")
Dialog.DialogChoiceSelected:Connect(function(player, Dialog)
if Dialog.Name == "Choice2" then
Remote:FireServer("toolName")
end
end)