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
There are many things wrong with this that I need to point out.
Don’t do this in a localscript EVER, it will cause your game to break without you knowing why.
Don’t use humanoid:EquipTool , just parent the tool to the players backpack
You have to clone the tool or it won’t work for other players
game:GetService(‘Workspace’) is a huge waste of time, just use workspace.
You use a lot of WaitForChild , only use it for things it needs.
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.
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.
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
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 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 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