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"] = ""
},
},