Help making an NPC purchasing system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    How to check if a part that has a Price Int Value, is moved to a senor part on top of a counter by the player using a drag detector, when a dialouge choice from the shop-employee has been selected by the player. If the player selects Yes, it will remove money from the player’s Money leaderstat, and they can bring their items over to their base. If the player selects No, it will respawn those items back on the shelf and the player wont be able to leave without the items disapering. Kind of like Lumber Tycoon 2 based game, if you ever played that.

  2. What is the issue? Include screenshots / videos if possible!
    When I move the Basic Pickaxe that has a price Int Value of $8 over to the counter and talk to the Shop Employees dialouge choice, he doesnt do anything.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Looked at other Devforum posts and looked up things on Youtube.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Script inside the Model of the shop employee.

local dialog = script.Parent:WaitForChild("Head"):WaitForChild("Dialog"):WaitForChild("Yes")
local counter = script.Parent.Parent.Counter.Sensor



dialog.DialogChoiceSelected:Connect(function(player, choice) 
	
	if counter:GetTouchingParts():FindFirstChild("Price") then
		print("Shop working")
		player.leaderstats.Money = player.leaderstats.Money - counter:GetTouchingParts():FindFirstChild("Price")
	end
	
end)

Leaderboard Script:

local Players = game:GetService("Players")
local gui = game.StarterGui
local DataStoreService = game:GetService("DataStoreService")
local savedMoney = DataStoreService:GetDataStore("Money")
local savedHunger = DataStoreService:GetDataStore("Hunger")

local random = math.random(1, 1)
local statRandom = math.random(3, 10)

local function leaderboardSetup(player)
	local plrid = "id_"..player.UserId
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"

	local houseOwned = Instance.new("IntValue")
	houseOwned.Name = "Plot"
	houseOwned.Parent = leaderstats
	houseOwned.Value = 0

	local hunger = Instance.new("IntValue")
	hunger.Name = "Hunger"
	hunger.Parent = leaderstats
	hunger.Value = 100

	local water = Instance.new("IntValue")
	water.Name = "Hydration"
	water.Parent = leaderstats
	water.Value = 100

	local success, currentExperience = pcall(function()
		return savedMoney:GetAsync(plrid)
	end)
	money.Value = currentExperience
	money.Parent = leaderstats

	while true do
		wait(3)
		money.Value = money.Value + 20
		print("Money given")
		print(money.Value)
		local success, errorMessage = pcall(function()
			savedMoney:SetAsync(plrid, money.Value)
		end)

	end


	local success, currentExperience = pcall(function()
		return savedHunger:GetAsync(plrid)
	end)
	hunger.Value = currentExperience
	hunger.Parent = leaderstats

	while true do
		wait(1)
		hunger.Value = hunger.Value - statRandom
		print("Lost hunger stat!")
		print(hunger.Value)
		local success, errorMessage = pcall(function()
			savedHunger:SetAsync(plrid, money.Value)
		end)

	end




end

-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
Players.PlayerAdded:Connect(leaderboardSetup)

Also, if you can, can you also help me able to make a Drag Detector be able to move on all three axis. Like X, Y, Z, instead of just 2 axis

Shop employee:
Screenshot 2024-01-28 103648

Counter:
Screenshot 2024-01-28 103729

Item Im trying to make purchaseable (in this case a basic pickaxe):
Screenshot 2024-01-28 104113

This script, it should be able to check all parts touching Sensor, see if they have a IntValue called Price, and if they do add them all up for a total price, The NPC will say the total price to them, and if they say Yes, it will take money off of their leaderstat for that much, and the owner of the item (the object value) will become the person who bought it, so no one else can be able to take it and or interact with it.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Wow, this was a long post for my first ever DevForum post!


Now I get stuck like this when playtesting for some reason…

And the money leaderstat is missing

I think it was just because Roblox was down for a sec, it working again now