2x Currency Gamepass does not Work

Hi there,

I am trying to develop a script by which the player’s awarded currency doubles based on the outcome of the match if they have bought a gamepass (e.g., 2x currency), and if they do not have it, they are awarded a standard amount.

However, the 2x currency scheme is not working when I test it on a Studio server, instead giving the standard amount of said currency to the player.

Below is my script for one of the teams in my game:

local Players = game.Players:GetPlayers()
local Player = game.Players.LocalPlayer
local TimesTwoCurrencyGamepass = 185750541

function module.MALWAREVictory()
	for i, Player in pairs(game.Players:GetPlayers()) do 
		if Player:FindFirstChild("MALWARE") then
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, TimesTwoCurrencyGamepass) then
				Player.Credits.Value = Player.Credits.Value + 250
			else
				Player.Credits.Value = Player.Credits.Value + 125
			end
		end
	end
end

I have looked at a number of articles and videos on this stuff, but it seems that gamepass scripts are done on a case-by-case basis.

3 Likes

Is this code in a server script or local script? I believe the main issue is that you have 2 variables of the same name (the Player variable). Ensure that this script is in a Server Script, as I believe MarketplaceService only runs on the server, and remove the LocalPlayer variable at the top of the script.

Edit:

I believe this is a module script, so make sure this function is being called from the server, and just change the second parameter of the for loop to something else like ‘plrs’.

Fixed Code:

local curPlayers = game.Players:GetPlayers()
--local LocalPlayer = game.Players.LocalPlayer -- uncomment this line only if the module script is also called from the client
local TimesTwoCurrencyGamepass = 185750541

function module.MALWAREVictory()
	for i, plrs in pairs(game.Players:GetPlayers()) do 
		if plrs:FindFirstChild("MALWARE") then
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plrs.UserId, TimesTwoCurrencyGamepass) then
				plrs.Credits.Value = Player.Credits.Value + 250
			else
				plrs.Credits.Value = Player.Credits.Value + 125
			end
		end
	end
end

What i recommend doing is creating a folder inside of the player which can be called whatever you want, then when the player joins, create a bool value like “DoubleMoneyPass” or any name for that matter, then set its value to true or false depending if the player has the gamepass, a way you can do this is:

local TimesTwoCurrencyGamepass = 185750541
local marketPlaceService = game:GetService("MarketplaceService")
local hasPass= player.folder.HasDoublePass

local success, message = pcall(function()
     hasPass.Value = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, TimesTwoCurrencyGamepass)
end)
if success then
  print("Has gamepass!")
else
  print("No Gamepass!")
end

EDIT: i noticed just now its a module script.

2 Likes

I tried your’s and @BabyNinjaTime’s methods, but they do not work. I am left with the exact outcome that made me prompt this topic.

You are correct - it is a module script - and this function is called without error in my main script.

Adding the BoolValue proved effective, but the module script does not know what to do with it.

Here is what things are looking like so far

Server Script (not main):

game.Players.PlayerAdded:Connect(function(Player)

-- Code...

	local TimesTwoCurrencyGamepass = 185750541
	local marketPlaceService = game:GetService("MarketplaceService")
	local hasPass = Instance.new("BoolValue", Player)
	hasPass.Name = "Has 2x Gamepass"

	local success, message = pcall(function()
		hasPass.Value = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, TimesTwoCurrencyGamepass)
	end)
	if success then
		print("Has gamepass!")
	else
		print("No Gamepass!")
	end

-- More code

end

Module Script:

local CurrentPlayers = game.Players:GetPlayers()
local TimesTwoCurrencyGamepass = 185750541

function module.MALWAREVictory()
	for i, plrs in pairs(game.Players:GetPlayers()) do 
		if plrs:FindFirstChild("MALWARE") then
			if plrs["Has 2x Gamepass"] == true then
				plrs.Credits.Value = plrs.Credits.Value + 250
			else
				plrs.Credits.Value = plrs.Credits.Value + 125
			end
		end
	end
end

Could we see the code that calls the module? There may be an issue around there.

1 Like

Sure thing!

local RoundTime = 300 -- How long the map will remain in the workspace
	for i = RoundTime, 0, -1 do
		Status.Value = "The Agents must Terminate the Malware within the Time Limit"
		local Mactive = false
		local Agents = {}
		for i, Player in pairs(game.Players:GetPlayers()) do
			if Player:FindFirstChild("Agent") then
				table.insert(Agents, Player)
			elseif Player:FindFirstChild("MALWARE") then
				Mactive = true
			end
		end
		if not Mactive then
			Status.Value = "The Agents have terminated the Malware!"
			Round.AgentVictory()
			task.wait(5)
			break
		end
		if #Agents == 0 then
			Status.Value = "The Malware has Eliminated the Agents!"
			Round.MALWAREVictory() -- Particular module function being called in the module script that I previously showed you
			task.wait(5)
			break

-- bunch of if statements, etc.

Timer.Value = toMS(i)
	task.wait(1)
end

1 Like

Hiya!

This is just a bump; is anyone else able to chime in and help out?

1 Like

Out of curiosity, because it is a module, have you ran “require()” on the module itself?

1 Like

Yes, I have run that code.

local Round = require(script.RoundModule)
1 Like

From what I’m seeing, “has 2x pass” is a boolvalue but it’s not checked as the value but rather the object itself.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.