Hello everyone, my name is Spideyalvaro999
Yesterday, I was testing the new shop I created on my game but it has a probelm. I use this leaderstats(they include the leaderstats, the data store and some remote events from another thing, nothing relevant).This is the script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local shopItems = game:GetService("ServerStorage"):WaitForChild("ShopItems") -- Where tools are held
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue",leaderstats)
points.Name = "Points"
points.Value = ds:GetAsync(player.UserId)or 0
ds:SetAsync(player.UserId, points.Value)
points.Changed:connect(function()
ds:SetAsync(player.UserId, points.Value)
end)
while true do
wait(20)
points.Value = points.value + 1
end
end)
game.Players.PlayerRemoving:Connect(function(player)
ds:SetAsync(player.UserId, player.leaderstats.point.Value)
end)
replicatedStorage.GetInfo.OnServerInvoke = function(player,item)
return shopItems[item].Points.Value
end
replicatedStorage.CheckSale.OnServerInvoke = function(player,item)
local price = shopItems[item].Points.Value
if player.leaderstats.Points.Value >= price then
player.leaderstats.Points.Value = player.leaderstats.Points.Value - price
local gear = shopItems[item][item]:Clone()
gear.Parent = player.StarterGear
local gear = shopItems[item][item]:Clone()
gear.Parent = player.Backpack
return true
else
return false
end
end
So the problem here is this one. When I’m going to buy something on the shop it substract the money from the leaderstats as I programmed, but after 20 seconds, a point is added(as I pogrammed) but instead of adding it to the amount with the money already subtracted from the purchase in the store, it is added to the amount you had before making the purchase in the store.
This is the script of the store. It only use one script that is the buy button:
local player = game:GetService(“Players”).LocalPlayer
script.Parent.MouseButton1Click:Connect(function(click)
if player.leaderstats.Points.Value >= 400 then
player.leaderstats.Points.Value = player.leaderstats.Points.Value - 400
game.ReplicatedStorage.Library.AGodSword:Clone().Parent = player:WaitForChild("Backpack")
end
end)
I’ve done a lot of things to solve the problem but it didnt worked anything. Do you know how to solve it? Please help me
Thanks for spending your time with this post
Spideyalvaro999