Hello! So, I have a store system and a currency system, the “problem” I’m having is that the currency, when used in the store, is only spent on the client-side (Because, the script that manages this is a LocalScript), but not on the server-side. Which is a big problem for datastore etc. I want to know how I could affect server-side spending as well. Thanks!
ShopConfigurations
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopSystem = ReplicatedStorage.ShopSystem
local ShopItems = ShopSystem.ShopItems
local ShopModule = {
Grasslands = {
ItemOne = {
ItemOne = ShopItems.Grasslands.ToolOne;
Cost = 250
};
ItemTwo = {
ItemTwo = ShopItems.Grasslands.ToolTwo;
Cost = 300
};
ItemThree = {
ItemThree = ShopItems.Grasslands.ToolThree;
Cost = 350
};
ItemFour = {
ItemFour = ShopItems.Grasslands.ToolFour;
Cost = 400
};
ItemFive = {
ItemFive = ShopItems.Grasslands.ToolFive;
Cost = 450
};
ItemSix = {
ItemSix = ShopItems.Grasslands.ToolSix;
Cost = 500
};
ItemSeven = {
ItemSeven = ShopItems.Grasslands.ToolSeven;
Cost = 550
};
ItemEight = {
ItemEight = ShopItems.Grasslands.ToolEight;
Cost = 600
};
ItemNine = {
ItemNine = ShopItems.Grasslands.ToolNine;
Cost = 650
};
ItemTen = {
ItemTen = ShopItems.Grasslands.ToolTen;
Cost = 700
}
}
}
return ShopModule
ShopHandle
--Variables.
local ShopGui = script.Parent.Parent
local Frame = ShopGui.Frame
local PlayerService = game:GetService("Players")
--
local ShopConfigurations = ShopGui.ShopConfigurations
local ShopModule = require(ShopConfigurations)
--
local BuyButtonTable = {
BuyButtonOne = Frame:FindFirstChild("BuyFrameOne");
BuyButtonTwo = Frame:FindFirstChild("BuyFrameTwo");
BuyButtonThree = Frame:WaitForChild("BuyFrameThree");
BuyButtonFour = Frame:FindFirstChild("BuyFrameFour");
BuyButtonFive = Frame:FindFirstChild("BuyFrameFive");
BuyButtonSix = Frame:FindFirstChild("BuyFrameSix");
BuyButtonSeven = Frame:FindFirstChild("BuyFrameSeven");
BuyButtonEight = Frame:FindFirstChild("BuyFrameEight");
BuyButtonNine = Frame:FindFirstChild("BuyFrameNine");
BuyButtonTen = Frame:FindFirstChild("BuyFrameTen")
}
--
local PlayerService = game:GetService("Players")
local LocalPlayer = PlayerService.LocalPlayer
local PlayerBackpack = LocalPlayer.Backpack
--
local CurrencyFolder = LocalPlayer:WaitForChild("CurrencyFolder")
--
local GoldCurrency = CurrencyFolder:WaitForChild("GoldCurrency")
local GoldCurrency = CurrencyFolder:WaitForChild("GoldCurrency")
--
BuyButtonTable.BuyButtonOne.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemOne.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemOne.Cost
BuyButtonTable.BuyButtonOne.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonOne.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonOne.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemOne.ItemOne:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonTwo.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemTwo.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemTwo.Cost
BuyButtonTable.BuyButtonTwo.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonTwo.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonTwo.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemTwo.ItemTwo:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonThree.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemThree.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemThree.Cost
BuyButtonTable.BuyButtonThree.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonThree.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonThree.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemThree.ItemThree:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonFour.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemFour.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemFour.Cost
BuyButtonTable.BuyButtonFour.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonFour.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonFour.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemFour.ItemFour:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonFive.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemFive.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemFive.Cost
BuyButtonTable.BuyButtonFive.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonFive.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonFive.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemFive.ItemFive:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonSix.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemSix.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemSix.Cost
BuyButtonTable.BuyButtonSix.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonSix.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonSix.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemSix.ItemSix:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonSeven.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemSeven.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemSeven.Cost
BuyButtonTable.BuyButtonSeven.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonSeven.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonSeven.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemSeven.ItemSeven:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonEight.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemEight.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemEight.Cost
BuyButtonTable.BuyButtonEight.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonEight.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonEight.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemEight.ItemEight:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonNine.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemNine.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemNine.Cost
BuyButtonTable.BuyButtonNine.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonNine.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonNine.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemNine.ItemNine:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
BuyButtonTable.BuyButtonTen.BuyButton.MouseButton1Click:Connect(function()
if GoldCurrency.Value >= ShopModule.Grasslands.ItemTen.Cost then
GoldCurrency.Value = GoldCurrency.Value - ShopModule.Grasslands.ItemTen.Cost
BuyButtonTable.BuyButtonTen.OwnedLabel.Transparency = 0.3
BuyButtonTable.BuyButtonTen.OwnedLabel.TextTransparency = 0
BuyButtonTable.BuyButtonTen.Interactable = false
local ToolClone = ShopModule.Grasslands.ItemTen.ItemTen:Clone()
ToolClone.Parent = PlayerBackpack
end
end)
PrincipalCurrency
--Variables.
local PlayerService = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetDataStore("Data")
--
--Functions.
PlayerService.PlayerAdded:Connect(function(Player)
local CurrencyFolder = Instance.new("Folder")
CurrencyFolder.Name = "CurrencyFolder"
CurrencyFolder.Parent = Player
local GoldCurrency = Instance.new("IntValue")
GoldCurrency.Name = "GoldCurrency"
GoldCurrency.Parent = CurrencyFolder
local GemCurrency = Instance.new("IntValue")
GemCurrency.Name = "GemCurrency"
GemCurrency.Parent = CurrencyFolder
---------------------------------------------
local Data = Data:GetAsync(Player.UserId)
if Data then
if Data[1] and Data[2] then
GoldCurrency.Value = Data[1]
GemCurrency.Value = Data[2]
end
end
GoldCurrency.Changed:Connect(function()
GoldCurrency. Value = math.clamp(GoldCurrency.Value, 0, 10000)
end)
GemCurrency.Changed:Connect(function()
GemCurrency. Value = math.clamp(GemCurrency.Value, 0, 5000)
end)
end)
PlayerService.PlayerRemoving:Connect(function(Player)
local CurrencyFolder = Player:WaitForChild("CurrencyFolder")
local GoldCurrency = CurrencyFolder:WaitForChild("GoldCurrency")
local GemCurrency = CurrencyFolder:WaitForChild("GemCurrency")
Data:SetAsync(Player.UserId, {GoldCurrency.Value, GemCurrency.Value})
end)
--