Adding gamepass to tycoon

Hello. I am currently working on a tycoon that needs a couple gamepasses such as “2x Cash” and “Auto Cash Collector”. Most of the code is from GamerM8 tutorial so check it out if you need further guidance.

This is the Main script that contains all function including the Cash function which I am pretty sure is where I need to edit to check for the gamepasses and grant them if the player purchases them.

local TycoonModel = script.Parent.Parent
local items = {}

local Boughtitems = TycoonModel:FindFirstChild("Boughtitems")
local Buttons = TycoonModel:FindFirstChild("Buttons")
local DropperParts = TycoonModel:FindFirstChild("DropperParts")
local Mainitems = TycoonModel:FindFirstChild("Mainitems")
local Scripts = TycoonModel:FindFirstChild("Scripts")
local Values = TycoonModel:FindFirstChild("Values")




--Tycoon Clone--

local TycoonClone = TycoonModel:Clone()
TycoonClone.Parent = game.ReplicatedStorage


--- Owner Functions ---

Mainitems.OwnerDoor.MainDoor.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") and Values.OwnerValue.Value == nil then
		local player = game.Players:GetPlayerFromCharacter(Hit.Parent)

		if player:FindFirstChild("OwnsTycoon").Value == false then

			Values.OwnerValue.Value = player

			player:FindFirstChild("OwnsTycoon").Value = true 

			while wait() do
				Mainitems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value).."'s Tycoon"
			end
		end
	end
end)




--Buying Functions--

for i, v in pairs(Buttons:GetChildren()) do
	local NewItem = Boughtitems:FindFirstChild(v.Item.Value)
	if NewItem ~= nil then

		items[NewItem.Name] = NewItem:Clone()

		NewItem:Destroy()

	else

		v.ButtonPart.Transparency = 1

		v.ButtonPart.CanCollide = false

		v.ButtonPart.BillboardGui.Frame.Visible = false


	end

	if v:FindFirstChild("Dependency") then

		coroutine.resume(coroutine.create(function()

			v.ButtonPart.Transparency = 1

			v.ButtonPart.CanCollide = false

			v.ButtonPart.BillboardGui.Frame.Visible = false

			if Boughtitems:WaitForChild(v.Dependency.Value, 1000000) then

				v.ButtonPart.Transparency = 0

				v.ButtonPart.CanCollide = true

				v.ButtonPart.BillboardGui.Frame.Visible = true
			end
		end))
	end

	v.ButtonPart. Touched:Connect(function(Hit)

		if Hit.Parent:FindFirstChild("Humanoid") then

			local player = game.Players:GetPlayerFromCharacter(Hit.Parent)

			if Values.OwnerValue.Value == player then

				if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then

					if player:WaitForChild("leaderstats").Tix.Value >= v.Price.Value then

						player.leaderstats.Tix.Value -= v.Price.Value

						items[v.Item.Value].Parent = Boughtitems

						v:Destroy()
					end
				end
			end
		end
	end)
end



--Cash Function--



local Debounce = false

Mainitems.CashButton.ButtonPart.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then 
		local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Values.OwnerValue.Value == player then
			if Debounce == false then
				Debounce = true
				player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value
				wait()
				Values.CashValue.Value = 0
				wait(1)
				Debounce = false
			end
		end
	end 

end)

while wait() do
	Mainitems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end

The 2x cash is tricky because the button that displays (surfacegui) the amount of cash you have needs to also multiply with the cash.

Try This And Write Answer


--Code: Script, Not LocalScript

local MPS = game:GetService("MarketplaceService") -- MarketPlaceService
local player = game.Players:GetChildren()[0] -- Put here your player (not character)
local gamepassID = 0000 -- Gamepass ID


if MPS:UserOwnsGamePassAsync(player.UserID, gamepassID) then
	--If user Own, Write here Code
else
	--If user NOT Own, Write here code
end

Once you have checked if the user owns the gamepass like TheAbovest explained, you should then track their ownership of the gamepass in a table.

Once you have done that, the above code could look something like this.

if doubleCash[player.UserId] ~= nil then
    player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value * 2
else
     player:WaitForChild("leaderstats").Tix.Value += Values.CashValue.Value
end

what is this replacing from the original code?