Ok, I found the solution.
The problem is that you can’t do DialogChoiceSelected in a server script, but on the other hand we can’t remove something from a player’s inventory on the client. For this type of cases it’s best to use a remote event.
- Add a remote event called “RemoveApple” inside ReplicatedStorage.
- Add LocalScript inside StarterPlayer > StarterPlayerScripts.
- Add Script inside apple dialogue.
Inside LocalScript:
-- By minefran50
wait(2)
local dialog = game:GetService("Workspace").Dummy:WaitForChild("Head").apple
local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoveApple")
dialog.DialogChoiceSelected:Connect(function(player, choice)
if choice == dialog.give then
Event:FireServer()
print("Choiced!")
else
print("Choice is not 'give'")
end
end)
Inside Script:
-- By minefran50
wait(1)
local Dummy = script.Parent.Parent.Parent
local AppleEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoveApple")
local ToolName = "Apple"
AppleEvent.OnServerEvent:Connect(function(plr)
if plr.Backpack:FindFirstChild(ToolName) then
-- Find on backpack
local tool = plr.Backpack:FindFirstChild(ToolName)
tool.Parent = Dummy
elseif plr.Character:FindFirstChild(ToolName) then
-- Find on character
local tool = plr.Character:FindFirstChild(ToolName)
tool.Parent = Dummy
end
end)
Now try this and tell me!