I’m trying to make it so if a npc chats what tool they want, if someone clicks on the npc then
check if they chatted the right tool, if not then npc chats, i didn’t order this and then jumps once then goes to a part. if the player brings the right food, then the npc equips the tool and after 10 seconds, they stop equipping it and it gets deleted or destoryed and the npc can say “thanks for the food” and pays you 100 - 500 cash.
This is my Code that didnt work:
local plr = game.Players.LocalPlayer
local npc = game.Workspace["Franklin Walking From Part To Part"]
local click = npc.ClickDetector
local tool = plr.Backpack.Part
local Chat = game:GetService("Chat")
local Text = "Can i get Part"
click.Parent.ProximityPrompt.Triggered:Connect(function()
if tool.Equipped then
if tool then
if Chat:Chat(npc.Head, Text, Enum.ChatColor.White) then
tool.Equipped:Connect(function()
npc.Humanoid:EquipTool(tool)
end)
end
end
end)
1: Tool.Equipped is not a boolean, it’s a RBX signal (see here for docs). If you check for just ‘Tool.Equipped’, then the first if statement sees that Tool.Equipped does not equal nil, and so the statement continues regardless of whether or not the tool is actually equipped.
2: Chat:Chat() does not return anything. The 3rd if statement is checking if nil is true, which it isn’t, so the code after that point will never run.
local plr = game.Players.LocalPlayer
local npc = game.Workspace["Franklin Walking From Part To Part"]
local click = npc.ClickDetector
local tool = plr.Backpack.Part
local Chat = game:GetService("Chat")
local Text = "Can i get Part"
click.Parent.ProximityPrompt.Triggered:Connect(function()
tool.Equipped.Wait()
Chat:Chat(npc.Head, Text, Enum.ChatColor.White)
npc.Humanoid:EquipTool(tool)
end)