IntValue is not Increasing/Decreasing Properly?

The IntValue (which is inside the player, (the name of that IntValue is ‘Skips’)), should increase by the amount of Skips a player bought.

Here is the issue:
The player starts of with 3 free skips. Once they use those 3 skips, they may want to buy let’s suppose 2 more skips. Now the IntValue before was 3 which is now 0 because they used their skips. And after they bought 2 skips through a developer product, they are supposed to have 2 skips. Because they bought 2 skips after finishing their default 3 skips. * But they don’t have 2 skips now (in their IntValue), instead, they have 5*.

But they are supposed to get 2.

I think that this is because the IntValue still has 3 skips but it is showing that the player has 0 skips so when the player buys 2 more skips. It’s adds it with 3 and not with 0.

Let me give you just one more example. Now the player has 5 skips left and he uses 2 skips. So he has 3 left. Now he buys 2 more skips and the IntValue changes from 3 to 7. The IntValue is considering the value still 5 despite showing 3. And when the player buys 2 skips, it adds it with the 5 skips.

This is the developer products page, which gives the player the additional skips (normal script):

local MarketPlaceService = game:GetService("MarketplaceService")

MarketPlaceService.ProcessReceipt = function(receiptInfo)

        if receiptInfo.ProductId == (Id of the product (I have added it correctly ) then

		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		player.SkipStages.Skips.Value += 1
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	elseif receiptInfo.ProductId == (Id of the product (I have added it correctly)) then

		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)		
		player.SkipStages.Skips.Value += 2
		return Enum.ProductPurchaseDecision.PurchaseGranted

	end
end

Although I have a local script inside a gui which when the player click (the textbutton), this local script get’s run:

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats"):FindFirstChild("Stage")
local skipStages =  player:WaitForChild("SkipStages"):FindFirstChild("Skips")
local hasLimits = true
local Limits = skipStages.Value
local maxLevels = game.Workspace.MaxStages.Value -- This is the total amount of stages in the game.

script.Parent.MouseButton1Click:Connect(function()
	print("Clicked!")
	if hasLimits == true then
		print("Has Limits == true!")
		if leaderstats.Value < maxLevels then
		
			print("Limits is greater than 0!")
			if skipStages.Value > 0 then
				leaderstats.Value = leaderstats.Value + 1
				skipStages.Value = skipStages.Value - 1 -- HERE IT IS. THE CODE THAT SUBTRACTS THE AMOUNT OF SKIPS THE PLAYER HAS.
				print("Subtracted Limits!")
				if player ~= nil then
					print("Player is not nil")
					if player.Character ~= nil then
						print("Players character is not nil")
						if player.Character:FindFirstChild("Humanoid").Health > 0 then
							print(player.Character)
							player.Character.HumanoidRootPart.CFrame = game.Workspace.Checkpoints:FindFirstChild(leaderstats.Value).CFrame + Vector3.new(0,3,0)
							print("You should have been teleported!")
						end
					end
				end
			else
					script.Parent.Parent.NotEnoughSkipsLeft.Visible = true
				if player ~= nil then
					if player.Character ~= nil then
						if player.Character:FindFirstChild("Humanoid").Health > 0 then
							player.Character.HumanoidRootPart.CFrame = game.Workspace.Checkpoints:FindFirstChild(leaderstats.Value).CFrame + Vector3.new(0,3,0)
						end
					end
				end
			end
		end
	end
end)

And just in case you needed the script which creates the Skips value (normal script):

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

Thanks for any help

1 Like

The problem is likely that your skips are not being saved. If you want the number of skips to be saved, you can use DataStores.

Another issue may be that you are subtracting the skips used by a player locally (in a localscript); this change does not replicate to the server, so you have to find a way to let the server know that you want to decrease the value. I would recommend using a RemoteEvent for this.

Of course, there could be another underlying issue. Do you suspect anything that may cause this behaviour? Can you provide more code to work with?

1 Like

I am using datastores but I have not added them in the question. Although I have a local script which subtracts the amount of skips the player has (it is a local script).And when a player click on the skip stage gui this local script get’s run and subtracts the values. Here, I will provide with the local script which subtracts the value of skips a player has:

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats"):FindFirstChild("Stage")
local skipStages =  player:WaitForChild("SkipStages"):FindFirstChild("Skips")
local hasLimits = true
local Limits = skipStages.Value
local maxLevels = game.Workspace.MaxStages.Value -- This is the total amount of stages in the game.

script.Parent.MouseButton1Click:Connect(function()
	print("Clicked!")
	if hasLimits == true then
		print("Has Limits == true!")
		if leaderstats.Value < maxLevels then
		
			print("Limits is greater than 0!")
			if skipStages.Value > 0 then
				leaderstats.Value = leaderstats.Value + 1
				skipStages.Value = skipStages.Value - 1 HERE IS IT. THE CODE THAT SUBTRACTS THE AMOUNT OF SKIPS A PLAYER HAS.
				print("Subtracted Limits!")
				if player ~= nil then
					print("Player is not nil")
					if player.Character ~= nil then
						print("Players character is not nil")
						if player.Character:FindFirstChild("Humanoid").Health > 0 then
							print(player.Character)
							player.Character.HumanoidRootPart.CFrame = game.Workspace.Checkpoints:FindFirstChild(leaderstats.Value).CFrame + Vector3.new(0,3,0)
							print("You should have been teleported!")
						end
					end
				end
			else
					script.Parent.Parent.NotEnoughSkipsLeft.Visible = true
				if player ~= nil then
					if player.Character ~= nil then
						if player.Character:FindFirstChild("Humanoid").Health > 0 then
							player.Character.HumanoidRootPart.CFrame = game.Workspace.Checkpoints:FindFirstChild(leaderstats.Value).CFrame + Vector3.new(0,3,0)
						end
					end
				end
			end
		end
	end
end)

It is inside a gui → LocalScript.

I think that because I am adding the values of skips through server and subtracting through a local script so maybe that’s the issue. Please correct me if I am wrong.

Hope this information helped.

You are correct in that the issue has to do with the LocalScript. @AbiZinho’s advice on the client-server model and RemoteEvents is the course of action you will need to take.

Basically, the only thing the client should do is send a request to the server that the player would like to skip. The server should then verify that the player has enough skips to do so and then move the player if they have enough skips or ignore the request if they don’t.

1 Like

Yes. I used RemoteEvents to fire to the server and now everything is working perfectly fine. Thank you everyone for your help