Script not running

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!

it works can u make it so he replies thank you

1 Like

so @minefran50 can u make it so if the apple tool is deleted, he says a new responsedialog saying thx, instead of the default on given which is bruh u dont have an apple, and make a remote event for the thx thing?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.