Help with 2x money gamepass

So in my game I want to add a 2x money gamepass. I am pretty new to scripting and I wasn’t sure how to include it in my already written code. So I watched a yt vid and it was rlly good, but I wasn’t sure how to add this into the already existing code. Here are the 2 different lines(First one is from the yt tutorial and second is from the game)

local function giveMoney(player)
player.leaderstats.Money.Value += (1 + player:FindFirstChild(“2xMoney”).Value)
There is more to the script but thats all that is important I think.

Ok and here is what im using to let players sell their sap for money:

script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local leaderstats = player:WaitForChild(“leaderstats”)
local money = leaderstats:FindFirstChild(“Money”)
local Sap = leaderstats:FindFirstChild(“Sap”)
if Sap.Value > 0 then
money.Value = money.Value + Sap.Value
Sap.Value = “0”
end
end
end)

Thank you in advance! If you wanna know anything about how things are referenced in other scripts or something, lmk.

And here is the game if you wanna have a look around! 🌲Tree Climbing Sim🌲 - Roblox

local doublePass = false
function checkPass()
 ---   check for gamepass
 ---   if true, set doublePass = true 
end checkPass()

script.Parent.Touched:Connect(function(hit)
---
local pay = Sap.Value
if doublePass then pay *= 2 end
money.Value += pay
---
3 Likes

How I would do it is, I would when you need to give some money I would check if they own the gamepass through the usage of UserOwnsGamePassAsync which is part of the marketplaceservice and then if they own the game pass just give them double the amount of money but if they don’t then just give them the normal amount.

On the top of my head I cannot remember if the UserOwnsGamePassAsync has any rate limit so you may need to just check when the user joins the server and then set that as a bool value or something like that if it does have a rate limit.

Ok thank you guys! I will try them!

Would you mind elaborating on how to set up the check pass function?

This might work, didn’t test anything here. (non-local script)

local MarketPlaceService = game:GetService("MarketplaceService")
local doublePass, gamepassID = false, 12345678 -- your gamepass id

function Spawned(player)
	local HasGamepass = false
	local success, message = pcall(function()
		HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
	end)
	
	task.wait(1)
	if not success then
		warn("Checking Gamepass "..tostring(message))
		return
	else
		doublePass = true
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		task.wait(3) Spawned(player)
	end)
end)

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local leaderstats = player:WaitForChild("leaderstats")
		local money = leaderstats:FindFirstChild("Money")
		local Sap = leaderstats:FindFirstChild("Sap")
		
		if Sap.Value > 0 then
			local pay = Sap.Value
			if doublePass then pay *= 2 end
			money.Value += pay
			Sap.Value = 0
		end
	end
end)

Trying not to hammer the server here. I take it the touched function is not possible within 4 seconds of a respawn or login. Script may need some love. Also tried to use as much of what you had as possible.

1 Like

Thank you so much! Ill test it out as soon as I can!

It worked! Thank you so much again!

For some reason everything is selling for double now

Ima just start a new topic for this

Didn’t you want a 2x money gamepass?
or did you want a 1/2 off game pass … replace *=2 for /=2

2x money… so *=2 cause the money needs to be multiplied by 2

It might be this part …
money.Value += pay

the way you had it would have been …
money.Value = money.Value + pay

Never tried that += on a .Value like that, not sure if it works.
Totally explain what you are doing here … post a video if you can.

Tbh, I dont feel like learning how to screen record and stuff on mac its not a very good system. So ill just tell you if thats alr. So basically, you collect sap from trees and go to the shop to sell the sap. I want a 2x money gamepass so when you sell the sap, it will give you 2x the money you would normally get.

Tell me if you wanna see any scripts or something in the game

Then that’s what you have the way it was from my post.
If you’re selling others things this is not to effect then you can’t use the same way for everything.

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