Gamepass + Rank Multiplier in DataStore2

Currently learning to use DataStore2 and having some issues applying a rank multiplier and a 2x gamepass.

Not sure if I need to explain but I am firing an event, detecting it and then Incrementing the total clicks by 1 which I then want to multiply by the rankMulti and x2 if gamepass is present.
rankMulti by default is 1

The error states

09:40:43.642 - Unable to cast Instance to int64
09:40:43.643 - Stack Begin
09:40:43.644 - Script ‘ServerScriptService.GameDataStore’, Line 79 - function onClickMe
09:40:43.644 - Stack End

Line 79 is marked at end of the line

The code where the error occurs
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local ClickMe = game.ReplicatedStorage:WaitForChild(“ClickMe”)

local function onClickMe(player)

	local defaultClick = 1 --Define the standard increment per click
	local rankMulti = DataStore2("rank", player)
	
	local clicksStore = DataStore2("clicks", player)
	
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player,5946406) then --LINE 79
		if rankMulti > 0 then
			clicksStore:Increment(1 * rankMulti * 2) --If gamepass apply additional x2
		end
	else
		if rankMulti > 0 then
			clicksStore:Increment(1 * rankMulti) --If no gamepass regular click x rankMulti
		end
	end
	
end

ClickMe.OnServerEvent:Connect(onClickMe)
1 Like
local function onClickMe(player)

	local defaultClick = 1 --Define the standard increment per click
	local rankMulti = DataStore2("rank", player)
	
	local clicksStore = DataStore2("clicks", player)
	
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player,5946406) then --LINE 79
		if rankMulti > 0 then
			clicksStore:Increment(1 * rankMulti:Get() * 2) --If gamepass apply additional x2
		end
	else
		if rankMulti > 0 then
			clicksStore:Increment(1 * rankMulti:Get()) --If no gamepass regular click x rankMulti
		end
	end
	
end

You can’t just add a datastore you need to get the info from the rank datastore using :Get()

1 Like

Ive changed the code every so slightly

Added .UserId when checking for gamepass
Added :Get() to the calls for the dataStore

Now I get no errors but the clicks also does not increase I was able to determine that none of the “print(“Hello”)” work, so for some reason my code is not passing the first rankMulti:Get() > 0 then

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClickMe = game.ReplicatedStorage:WaitForChild("ClickMe")

local function onClickMe(player)
	
	local defaultClick = 1 --Define the standard increment per click
	local rankMulti = DataStore2("rank", player)
	
	local clicksStore = DataStore2("clicks", player)
	
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 5946406) then --LINE 79
		if rankMulti:Get() > 0 then
			print("hello")
			clicksStore:Increment(1 * rankMulti:Get() * 2) --If gamepass apply additional x2
		end
	else
		if rankMulti:Get() > 0 then
			print("hi2")
			clicksStore:Increment(1 * rankMulti:Get()) --If no gamepass regular click x rankMulti
		end
	end
	
end

ClickMe.OnServerEvent:Connect(onClickMe)