-- NPC Script
local questItems = {"Engine", "Battery", "Tire"}
local playerProgress = {}
local TextValue = 0
function updateBillboard(player, currentStep)
local billboard = script.Parent:FindFirstChild("Billboard")
if billboard then
local billboardGui = billboard:FindFirstChild("BillboardGui")
local label = billboardGui:FindFirstChild("TextLabel")
if label then
label.Text = TextValue .. "/3"
end
end
end
function onInteract(player)
local progressData = playerProgress[player.UserId] or {}
local currentStep = progressData.currentStep or 1
if not progressData.completed then
local requiredItem = questItems[currentStep]
local hasRequiredItem = player.Backpack:FindFirstChild(requiredItem)
if hasRequiredItem then
hasRequiredItem:Destroy()
progressData.currentStep = currentStep + 1
TextValue = TextValue + 1
if currentStep == #questItems then
progressData.completed = true
print("Quest completed! Items removed from your inventory.")
else
print("Good job! Now bring me a " .. questItems[currentStep + 1] .. ".")
end
updateBillboard(player, progressData.currentStep)
else
print("You don't have the required item.")
end
playerProgress[player.UserId] = progressData
else
print("You have already completed the quest.")
end
end
local clickDetector = script.Parent:WaitForChild("ClickDetector")
clickDetector.MouseClick:Connect(function(player)
onInteract(player)
end)
its almost done, the only problem is i want the player to equip the tool and click on the npc through the server script not just use the click detector and click on the npc to give him the tools. I will pay 350 robux to someone who can help me with the fix.
u can use the hasRequiredItem conditional statement inside the event
clickDetector.MouseClick:Connect(function(player) --event
local progressData = playerProgress[player.UserId] or {}
local currentStep = progressData.currentStep or 1
if not progressData.completed then
local requiredItem = questItems[currentStep]
local hasRequiredItem =
player.Backpack:FindFirstChild(requiredItem)
--if player dont have the item, we cancel his request
if not hasRequiredItem then return end
--other code
I think the code u provided above should work, u just have to implement the tool equipped logic
clickDetector.MouseClick:Connect(function(player) --event
local progressData = playerProgress[player.UserId] or {}
local currentStep = progressData.currentStep or 1
if not progressData.completed then
local requiredItem = questItems[currentStep]
local hasRequiredItem =
player.Backpack:FindFirstChild(requiredItem)
--if player dont have the item, we cancel his request
if not hasRequiredItem then return end
--other code
alright so i was able to simply add it in but the thing is, it works the same as before. What i have right now is when the player picks up the 3 needed tools the only way they can give it to the npc is by having all the tools unequipped and clicking the click detector 3 times. I want the player to be able to give the tools but the only way they can give it is by equipping the tool and clicking the npc.
local questItems = {"EngineTool", "BatteryTool", "TireTool"} -- Updated with tool names
local playerProgress = {}
local TextValue = 0
function updateBillboard(player, currentStep)
-- billboard update logic
end
function onToolInteract(player, tool)
local progressData = playerProgress[player.UserId] or {}
local currentStep = progressData.currentStep or 1
if not progressData.completed and tool.Name == questItems[currentStep] then
tool:Destroy()
progressData.currentStep = currentStep + 1
TextValue = TextValue + 1
-- quest completion logic
updateBillboard(player, progressData.currentStep)
playerProgress[player.UserId] = progressData
else
print("You don't have the required tool or have already completed the quest.")
end
end
local function setupToolListener(tool)
tool.Equipped:Connect(function()
local clickDetector = script.Parent:WaitForChild("ClickDetector")
clickDetector.MouseClick:Connect(function(player)
onToolInteract(player, tool)
end)
end)
end
game.Players.PlayerAdded:Connect(function(player)
player.Backpack.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
setupToolListener(child)
end
end)
end)