Using, DataStore2
So, I'm setting up a store Gui and when you hit the buy button a local script activates a remote event., which then fires in my leaderstat script, and it takes 20 away from the gems value. The problem is, is that I can't seem to figure out how to make it so that it the player doesn't have 20 gems then they can't buy it, as it is now, it just goes -20, -40 and so on, I tried an if statement a couple of different, i tried it once in the local script, so that if gems.Value >= 20 then fire the event, but it fires wether there is 20 gems or not, then i tried in the leaderstat script, like, if gems.Value >= 20 then gemStore:Increment(-20) but it didnt work either, heres the two scripts without either if statements!
leaderstat Script
local Players = game:GetService('Players') local ServerScriptService = game:GetService('ServerScriptService') local Workspace = game:GetService("Workspace") local StarterGui = game:GetService("StarterGui") local DataStore2 = require(ServerScriptService.DataStore2) DataStore2.Combine("DATA", "clicks", "rebirths", "gems") Players.PlayerAdded:Connect(function(player) local clickStore = DataStore2("clicks", player) local rebirthStore = DataStore2("rebirths", player) local gemStore = DataStore2("gems", player) local leaderstats = Instance.new("Folder", player) leaderstats.Name = "leaderstats" local clicks = Instance.new("IntValue", leaderstats) clicks.Name = "Clicks" clicks.Value = clickStore:Get(0) local rebirths = Instance.new("IntValue", leaderstats) rebirths.Name = "Rebirths" rebirths.Value = rebirthStore:Get(0) local gems = Instance.new("IntValue", leaderstats) gems.Name = "Gems" gems.Value = gemStore:Get(0) clickStore:OnUpdate(function(newClicks) clicks.Value = newClicks end) rebirthStore:OnUpdate(function(newRebirths) rebirths.Value = newRebirths end) gemStore:OnUpdate(function(newGems) gems.Value = newGems end) end) game.ReplicatedStorage.AddClick.OnServerEvent:Connect(function(player) local multiplier = player:WaitForChild("multiply"):FindFirstChild("ClickMultiplier").Value local potionX = player:WaitForChild("multiply"):WaitForChild("PotionX").Value local clickStore = DataStore2("clicks", player) clickStore:Increment(multiplier + potionX) end) game.ReplicatedStorage.AddRebirths.OnServerEvent:Connect(function(player) local gemStore = DataStore2("gems", player) local clickStore = DataStore2("clicks", player) local clicks = player:WaitForChild("leaderstats"):WaitForChild("Clicks") local rebirthStore = DataStore2("rebirths", player) rebirthStore:Increment(1) clickStore:Set(0) gemStore:Increment(10) end) -- takes gems away from overall value!!! game.ReplicatedStorage.gemMultiply.OnServerEvent:Connect(function(player) local gemStore = DataStore2("gems", player) gemStore:Increment(-20) end) game.Workspace.ResetStat.ClickDetector.MouseClick:Connect(function(player) local gemStore = DataStore2("gems", player) gemStore:Set(0) end)
localscript in Potion Store Gui
script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.gemMultiply:FireServer() end)
i think this should work for you Gem is the Gem count
local buyPrice = 20 game.ReplicatedStorage.gemMultiply.OnServerEvent:Connect(function(player) local gemStore = DataStore2("gems", player) local Gems = player.leaderstats.Gems.Value if Gems > buyPrice or Gems == buyPrice then gemStore:Increment(-buyPrice) else print("Player dont have enough gems") end end)