Dialog System not working

So i have been working so if a player talks to a NPC they get a package and have to deliver it. I am actually making it for another person. But it doesn’t seen to work.

Here’s the code-

--Made By Beastcraft_Gaming
local Dialog = game:GetService("Workspace"):WaitForChild("Dummy1"):WaitForChild("Head"):WaitForChild("DeliveryManager")
local tool = game:GetService("ReplicatedStorage"):WaitForChild("Package")
local player = game:GetService("Players").LocalPlayer
print("Script is working1") --Prints
Dialog.DialogChoiceSelected:Connect(function(player, DialogChoice)
	print("Event fired")--Prints
	if DialogChoice.Name == "Okay" then
		print("Player selected Okay")--Doesn't Prints
		local char = player.Character or player.CharacterAdded:Wait()
		local hum = char:FindFirstChild("Humanoid")
		if hum then
			hum:EquipTool(tool)
		end
	end
end)


Yeah it is in a local script and the local script is located in starter player script.

And it has no errors.
Any help will be appreciated :smiley:

There are many things wrong with this that I need to point out.

  1. Don’t do this in a localscript EVER, it will cause your game to break without you knowing why.
  2. Don’t use humanoid:EquipTool , just parent the tool to the players backpack
  3. You have to clone the tool or it won’t work for other players
  4. game:GetService(‘Workspace’) is a huge waste of time, just use workspace.
  5. You use a lot of WaitForChild , only use it for things it needs.
  6. Try using workspace and just game.Players
--Made By Beastcraft_Gaming
local Dialog = workspace.Dummy1.Head.DeliveryManager
local tool = game:GetService("ReplicatedStorage"):WaitForChild("Package"):Clone()
local player = game.Players.LocalPlayer
Dialog.DialogChoiceSelected:Connect(function(player, DialogChoice)
	print("Event fired")--Prints
        print(DialogueChoice.Name)
	if DialogChoice.Name == "Okay" then
		print("Player selected Okay")--Doesn't Prints
		tool.Parent = player.Backpack
	end
end)

Put this into a regular script in workspace, and please tell me what prints right after “Event Fired” In output so I can adjust it.

What? If he wants to make the dialog appear for the client who invoked whatever then running it on localscript is fine. Please tell me how it would break

He is… equipping the tool? Cloning a tool would not make the humanoid automatically equip it.

but its written here this event will only fire in local script.

I am doing it cauze for exploiting prevention i kust put a script which will change the name of the game.[Child] to random characters

Okay so i tried on script in a server script in workspace it didn’t worked nor printed anything.

Why everyone stopped replying its not sloved yet.

It’s not printing because the if statement is not firing. Check your dialogue names again.

Broken code does not belong in Code Review, please read category guidelines before posting threads. I have recategorised the thread to Scripting Support, which is where you should post if you need help with resolving problems in your code.

I am extremely sorry i am new to devforum. I will keep in mind next time.

Could you Try printing the DialogChoice.Name once before the print, and check if its the same?

Otherwise as @dibblydubblydoo said you probably haven’t named it correctly.

I am not on pc rn i will check the name ASAP.

1 Like

How is that exploiting protection? Exploit protection is usually only done on the server as the client cannot modify things, if you use a localscript, the client could modify or delete it.

Also, I said don’t use a localscript for it because tools won’t replicate properly

1 Like

It more than likely doesn’t print because the name of DialogChoice isn’t "Okay". And you are calling that print function inside the scope of that if statement that checks if the DialogChoice’s name is “Okay”.

you can use that only if you using local script.

If the exploit is using game.[child.Name]. It will give error cuz we have changed all names i read this on a post.

You will want to do the Dialog Client sided, but the tool cloning part should be done in the Server Side, or as @infiniteRaymond has said you will get alot of replication issues later on.

So what you can do is fire a remote event on the dialog Choice connection after the if condition, that equips the tool.

Okay so heres the snip of the properties tab of dialog
image

And i printed (DialogChoice.Name) it printed this
image

Okay, so you are basically checking if the Name is “Okay” which its not but, the UserDialog is “Okay”, so maybe you want to check that and not the name


@infiniteRaymond Some mistakes that you have in your reply, the Dialog has to be done client sided. And another is that workspace over game:GetService(“Workspace”) isn’t really a good practice. You can see this post here: https://devforum.roblox.com/t/what-are-bad-programming-habits-that-you-see-often-by-scripters/761033/92

You are getting the name of the DialogChoice instance, not the dialog choice. Try if UserDialog == "Okay" then