Help with updating gamepass multiplier loop

Opps, didn’t even read about that. Took a quick skim but it looks like your creating a connection variable and setting it to nil:

You then aren’t using this variable at all. E.g you aren’t doing:

Connection = MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(plr, id, purchased)

Then later in your script you’re disconnecting the “Connection” variables even tho its value is still nil. You’re basically doing nil:Disconnect().

You pretty much have to just add the Connection = in front of your marketplace connection OR you could just move the entire function outside the playerAdded connection (which i recommend) and ditch the whole :Disconnect() and Connection variable.

If theres any other thing I missed just point it out and provide the exact error and line where its coming from!

Ok so I took your advice and took a different approach at this. This is my new script:

local RunService = game:GetService("RunService")
local MarketPlaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")

function hasVIP(player)

	local PlayerStats = player:WaitForChild('PlayerStats')
	local XP = PlayerStats:WaitForChild('XP')
	local Coins = PlayerStats:WaitForChild('Coins')
	local CoinsVIPMulti = PlayerStats:WaitForChild('CoinsVIPMulti').Value
	local XPVIPMulti = PlayerStats:WaitForChild('XPVIPMulti').Value
	local CoinsPremiumMulti = PlayerStats:WaitForChild('CoinsPremiumMulti').Value
	local XPPremiumMulti = PlayerStats:WaitForChild('XPPremiumMulti').Value
	local TotalCoinsMulti = PlayerStats:WaitForChild('TotalCoinsMulti').Value
	local TotalXPMulti = PlayerStats:WaitForChild('TotalXPMulti').Value

	CoinsVIPMulti = 1.5
	XPVIPMulti = 1.5

	CoinsPremiumMulti = 0
	XPPremiumMulti = 0

	if player.MembershipType == Enum.MembershipType.Premium then

		CoinsPremiumMulti = 0.5
		XPPremiumMulti = 0.5
	end

	TotalCoinsMulti = CoinsVIPMulti + CoinsPremiumMulti
	TotalXPMulti = XPVIPMulti + XPPremiumMulti

	task.spawn(function() 		
		while true do
			
			Coins.Value += 5 * TotalCoinsMulti
			XP.Value += 5 * TotalXPMulti
			task.wait(2)
		end
	end)
end

function doesntHaveVIP(player)

	local PlayerStats = player:WaitForChild('PlayerStats')
	local XP = PlayerStats:WaitForChild('XP')
	local Coins = PlayerStats:WaitForChild('Coins')
	local CoinsVIPMulti = PlayerStats:WaitForChild('CoinsVIPMulti').Value
	local XPVIPMulti = PlayerStats:WaitForChild('XPVIPMulti').Value
	local CoinsPremiumMulti = PlayerStats:WaitForChild('CoinsPremiumMulti').Value
	local XPPremiumMulti = PlayerStats:WaitForChild('XPPremiumMulti').Value
	local TotalCoinsMulti = PlayerStats:WaitForChild('TotalCoinsMulti').Value
	local TotalXPMulti = PlayerStats:WaitForChild('TotalXPMulti').Value
	local OwnsVIP = PlayerStats:WaitForChild('OwnsVIP').Value

	local debounce = false

	CoinsVIPMulti = 1
	XPVIPMulti = 1

	CoinsPremiumMulti = 0
	XPPremiumMulti = 0

	if player.MembershipType == Enum.MembershipType.Premium then

		CoinsPremiumMulti = 0.5
		XPPremiumMulti = 0.5
	end

	TotalCoinsMulti = CoinsVIPMulti + CoinsPremiumMulti
	TotalXPMulti = XPVIPMulti + XPPremiumMulti

	task.spawn(function()
		while true do
			
			Coins.Value += 5 * TotalCoinsMulti
			XP.Value += 5 * TotalXPMulti
			task.wait(2)
			if OwnsVIP == true then
				break
			end
		end
	end)
end

players.PlayerAdded:Connect(function(player)

	local PlayerStats = player:WaitForChild('PlayerStats')
	local CoinsVIPMulti = PlayerStats:WaitForChild('CoinsVIPMulti')
	local XPVIPMulti = PlayerStats:WaitForChild('XPVIPMulti')
	local CoinsPremiumMulti = PlayerStats:WaitForChild('CoinsPremiumMulti')
	local XPPremiumMulti = PlayerStats:WaitForChild('XPPremiumMulti')

	if MarketPlaceService:UserOwnsGamePassAsync(player.UserId,27136394) then

		hasVIP(player)
	else

		doesntHaveVIP(player)
	end	
end)

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(plr, id, purchased)
	if id == 27136394 and purchased then
		
		plr.PlayerStats.OwnsVIP.Value = true
		hasVIP(plr)
	end
end)

It all works except for when a player buys VIP the loop at the function doesntHaveVIP() doesn’t break. Could you help?

I have looked everywhere and I think that the break should work but it just doesn’t?