I have a few scripts for my gear shop.
One of them is a Module script that separates the prices on each gear for players who have Roblox Premium and players who don’t.
The other module script (that requires the first module script) determines whether the player (depending on their membership status) has enough money to buy the gear. If they do, it gear clones into their backpack. If they don’t, nothing happens.
The problem is that they don’t work when the player clicks the button on the shop to buy the select tool.
Here are the scripts:
-- First Module Script, located in ServerStorage
-- Each Tool has its own button in the shop
local ToolSettings = {}
local Tools = game.ServerStorage.Tools
ToolSettings["Gravity Coil"] = {
Tool = Tools.GravityCoil;
Price = 50;
PremiumPrice = 25;
}
ToolSettings["DualGravityCoil"] = {
Tool = Tools.DualGravityCoil;
Price = 150;
PremiumPrice = 75;
}
ToolSettings["Regen Coil"] = {
Tool = Tools.RegenCoil;
Price = 50;
PremiumPrice = 25;
}
ToolSettings["DualRegenCoil"] = {
Tool = Tools.DualRegenCoil;
Price = 150;
PremiumPrice = 75;
}
ToolSettings["SpeedCoil"] = {
Tool = Tools.SpeedCoil;
Price = 50;
PremiumPrice = 25;
}
ToolSettings["DualSpeedCoil"] = {
Tool = Tools.DualSpeedCoil;
Price = 150;
PremiumPrice = 75;
}
ToolSettings["GreenLaserGun"] = {
Tool = Tools.GreenHyperLaser;
Price = 150;
PremiumPrice = 75;
}
ToolSettings["Ro-Orb"] = {
Tool = Tools["Ro-Orb"];
Price = 200;
PremiumPrice = 100;
}
ToolSettings["Railgun"] = {
Tool = Tools.Railgun;
Price = 350;
PremiumPrice = 175;
}
ToolSettings["Railgun2"] = {
Tool = Tools.Railgun2;
Price = 750;
PremiumPrice = 375;
}
ToolSettings["Railgun3"] = {
Tool = Tools.Railgun3;
Price = 2000;
PremiumPrice = 1000;
}
ToolSettings["Shotgun"] = {
Tool = Tools.Shotgun;
Price = 200;
PremiumPrice = 100;
}
ToolSettings["Shotgun2"] = {
Tool = Tools.Shotgun2;
Price = 500;
PremiumPrice = 250;
}
ToolSettings["Shotgun3"] = {
Tool = Tools.Shotgun3;
Price = 1000;
PremiumPrice = 500;
}
ToolSettings["Sniper"] = {
Tool = Tools.Sniper;
Price = 250;
PremiumPrice = 125;
}
ToolSettings["Sniper2"] = {
Tool = Tools.Sniper2;
Price = 750;
PremiumPrice = 375;
}
ToolSettings["Sniper3"] = {
Tool = Tools.Sniper3;
Price = 2000;
PremiumPrice = 1000;
}
ToolSettings["Crossbow"] = {
Tool = Tools.Crossbow;
Price = 100;
PremiumPrice = 50;
}
ToolSettings["CrossBow2"] = {
Tool = Tools.Crossbow2;
Price = 500;
PremiumPrice = 250;
}
ToolSettings["CrossBow3"] = {
Tool = Tools.Crossbow3;
Price = 1500;
PremiumPrice = 750;
}
ToolSettings["Grenade Launcher"] = {
Tool = Tools["Grenade Launcher"];
Price = 150;
PremiumPrice = 75;
}
ToolSettings["Grenade Launcher2"] = {
Tool = Tools["Grenade Launcher2"];
Price = 500;
PremiumPrice = 250;
}
ToolSettings["Grenade Launcher3"] = {
Tool = Tools["Grenade Launcher3"];
Price = 1250;
PremiumPrice = 625;
}
return ToolSettings
-- Second Module Script
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
-- Other Variables
local Tools = ServerStorage.Tools
local Membership = Enum.MembershipType
local None = Membership.None
local Premium = Membership.Premium
local ToolSettings = require(game.ServerStorage.ToolConfig)
ReplicatedStorage.BuyEvent.OnServerEvent:Connect(function(player, toolname)
local Setting = ToolSettings[toolname]
if not Setting then return end
local Price = (Membership == Premium and Setting.PremiumPrice) or Setting.Price
local Cash = player.leaderstats.Cash
local Backpack = player:WaitForChild("Backpack")
if Cash.Value >= Price then
Cash.Value -= Price
Setting.Tool:Clone().Parent = Backpack
end
end)
What am I doing wrong?