I have an IntValue inside the player. It is called "Skips". When I created the IntValue called ("Skips"), I gave the default value of it to 3. Like below (normal script):
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("SkipsDataStore")
game.Players.PlayerAdded:Connect(function(player)
local SkipStages = Instance.new("Folder", player)
SkipStages.Name = "SkipStages"
local Skips = Instance.new("IntValue", SkipStages)
Skips.Name = "Skips"
Skips.Value = 3
local data
local success, errormessage = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
if success then
Skips.Value = data.Skips
else
print("Error while fetching data!")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
local data = {
Skips = player.SkipStages.Skips.Value
}
DataStore:SetAsync(player.UserId, data)
end)
if success then
print("Skips Successfully Saved!")
else
print("There was an error while saving Skips!")
warn(errormessage)
end
end)
So as you can see the starting value of Skips is 3. So it means that the player can skip levels 3 times. Each time they skip a level, the value of 'Skips' decreases by 1. And once they have 0 skips left, they can't skip anymore.
But what they can do is, that they can buy more skips.
So here is the problem:
When the player buys more skips, let's say the player buys 2 more skips. The value of 'Skips' should be now 2. But is is not 2, it is 5.
As you can see, 3 is being added. Why is that so.
What I think is the problem:
I think it is because that I have added 3 as a default I guess, so it is adding 3 to the IntValue.
But why is that so?
Because those 3 skips have been used. And the value is now 0. So why does it consider it still 3 even when the value is 0. Is it because I am adding it through a script?
The IntValue is showing the value of 0 but when I buy skips, it still considers the 3 skips which are already used and thus, gives me 5 (because I bought 2 skips).
Why is this so? And how to go about solving this?
This is the developer products script. Which runs when the player buys more skips.
elseif receiptInfo.ProductId == (Id goes here) then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.SkipStages.Skips.Value += 1 -- This Developer product gives +1 skips to the 'Skips' IntValue.
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == (Id goes here) then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.SkipStages.Skips.Value += 2 -- This Developer product gives +2 skips to the 'Skips' IntValue.
return Enum.ProductPurchaseDecision.PurchaseGranted
end
Thanks for any help

4 comments
Can you show us your entire script? I think you left something important out.
I added the entire script which adds the 'skips' intvalue and which saves that intvalue. Check it out
The problem is that you're getting the same receiptinfo, so it adds up to 1, then 2. Next time, use this magical command called print() in order to find anything wrong.
So how can I go about the same receiptinfo? I have tried printing also.