Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't the IntValue increases/decreases properly?

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

0

Can you show us your entire script? I think you left something important out.

0

I added the entire script which adds the 'skips' intvalue and which saves that intvalue. Check it out

0

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.

0

So how can I go about the same receiptinfo? I have tried printing also.

1 answer

I bet you that what is happening is that the player is receiving both the one skip and the two skips. Check the developer product IDs again.

4 comments

0

The developer product id's are correct.

0

The thing is, that the value is not the same as the one which get's added. i.e. if I have 7 skips, I use 2. I have 5 left. The IntValue shows 5, as expected but if I buy 2 more skips, then I don't have 7. I have 9.

0

It still counts as 7 but shows 5

0

Well, then why are you showing us the code that increases the value of the skips? Show the code to change the text label. You need to explain your problems better.

This discussion is preserved as it was. New answers, comments, and votes are closed.