I need help with this detection code that would check if I can buy a certain item

So I wish to create a code that would detect when a player can buy a certain item (droppers, walls, conveyors, etc)

The code I tried out didn’t work at all, and I was wondering if someone could give me a code that would make it work and explain it a bit aswell.

Here is my current code:

manager Script:

local ownerId = 0

local moduleStats = require(game:GetService("ReplicatedStorage").Support.Statistics)
local prices = moduleStats.Items:GetDescendants("Price")
local names = moduleStats.Items:GetChildren()
task.defer(function(prices)
	while task.wait() do
		local plr = game:GetService("Players"):GetPlayerByUserId(ownerId)
		
		for _,buyable in pairs(names) do
			if plr.leaderstats.Tix.Value == prices and plr.TeamColor == tycoon:GetAttribute("TeamColor") then
				local sparkle = Instance.new("Sparkles")
				
				sparkle.Name = "Sparkles"
				sparkle.Parent = buyable
				sparkle.Enabled = true
			elseif plr.leaderstats.Tix.Value < prices and plr.TeamColor == tycoon:GetAttribute("TeamColor") then
				local sparkl = buyable:FindFirstChild("Sparkles")
				
				sparkl:Destroy()
			end
		end
	end
end)

Statistics module script:

	-- Items:
	["Items"] = {
		-- Buttons:
		["StarterDropper"] = {
			["Price"] = 0; -- 0
			["Text"] = "Tix mine";
			["Dependance"] = {"UpgradeMine", "Conveyor1", "Conveyor2", "Dropper2"};
			["Texture"] = ""
		},

		["Dropper2"] = {
			["Price"] = 50; -- 50
			["Text"] = "Tix Printer";
			["Dependance"] = {"Dropper3"};
			["Texture"] = "";
			["Interval"] = 2;
		},

		["Dropper3"] = {
			["Price"] = 125; -- 125
			["Text"] = "Tix Printer";
			["Dependance"] = "None";
			["Texture"] = "";
			["Interval"] = 1.5;
		},

		["Conveyor1"] = {
			["Price"] = 25; -- 25
			["Text"] = "Add Conveyor Walls";
			["Level"] = 1;
			["Dependance"] = "Conveyor3";
			["Texture"] = ""
		},

		["Conveyor2"] = {
			["Price"] = 100; -- 100
			["Text"] = "Faster Conveyors";
			["Level"] = 2;
			["Dependance"] = "Conveyor4";
			["Texture"] = "12338397019" -- http://www.roblox.com/asset/?id=12338397019
		},

		["Conveyor3"] = {
			["Price"] = 100; -- 100
			["Text"] = "Higher Conveyor Walls";
			["Level"] = 2;
			["Dependance"] = "None";
			["Texture"] = ""
		},

		["Conveyor4"] = {
			["Price"] = 200; -- 200
			["Text"] = "Even Faster Conveyors";
			["Level"] = 3;
			["Dependance"] = "None";
			["Texture"] = ""
		},
		-- Upgrades:
		["UpgradeMine"] = {
			["Price"] = 25; -- 25
			["Text"] = "Upgrade mine";
			["Level"] = 2;
			["DropSpeed"] = 0.55;
			["Dependance"] = "None";
			["Texture"] = ""
		},
	},
local Price = 500 -- the price of one of your items
local PlayersCash = 0
while wait(1) do
	--every second we will check
	if PlayersCash >= Price then
		print("Player can buy the item")
	end
	PlayersCash += 100--remove this when you are actually useing it
end

Just remove the players cash += and kind of implement it with your original code

Its rather that the script is supposed to only show you can buy it, I already made a buying script which functions the same as the one you just showed right now. But dw man, I already found a solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.