ive been working on a delivery system and the script works only for “Donut” not for “chocolateDonut” tought…
local Dummy1 = workspace.Dummy1
local npc = script.Parent -- Assumes the script is inside the NPC
local toolNames = {"Donut", "ChocolateDonut"} -- Add the names of your tools
-- Function to handle proximity prompt activation
local function onPromptActivated(player)
local backpack = player.Backpack
if backpack then
local cashStat = player:FindFirstChild("leaderstats")
if not cashStat then
warn("Leaderstats not found for player " .. player.Name)
return
end
for _, toolName in pairs(toolNames) do
local tools = backpack:GetChildren()
for _, tool in pairs(tools) do
if tool:IsA("Tool") and tool.Name == toolName then
local valueObject = tool:FindFirstChild("Value")
if valueObject and valueObject:IsA("NumberValue") then
local cashAmount = valueObject.Value
local cashValue = cashStat:FindFirstChild("Cash")
if not cashValue then
warn("Cash value not found in leaderstats for player " .. player.Name)
return
end
-- Add cash directly to the player's stat (modify this according to your game)
cashValue.Value = cashValue.Value + cashAmount
-- Display an overhead GUI with the cash amount over the NPC's head
local gui = Instance.new("BillboardGui")
gui.Size = UDim2.new(0, 200, 0, 50)
gui.Adornee = Dummy1 -- Change 'npc' to the reference of your NPC
gui.StudsOffset = Vector3.new(0, 2, 0)
local text = Instance.new("TextLabel")
text.Text = "Received $" .. cashAmount
text.Size = UDim2.new(1, 0, 1, 0)
text.TextScaled = true -- Adjusted to improve text clarity
text.TextStrokeTransparency = 0.5
text.Parent = gui
gui.Parent = game.Workspace
wait(3) -- Display the GUI for 3 seconds (adjust as needed)
gui:Destroy()
tool:Destroy()
end
end
end
end
end
end
-- Create the proximity prompt
local npc = script.Parent -- Assumes the script is inside the NPC
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Deliver"
prompt.Parent = npc
prompt.Triggered:Connect(onPromptActivated)