Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gamepass ownership update without rejoin game?

Hey there,

I've got this script that checks if a player owns the gamepass then would pass the code, But if you buy the gamepass while in-game it would not give the correct coins until they rejoin?

Is there a simple way to check if they bought it?

Script:
local MarketplaceService = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
local amount = 2
local timedelay = 5
local currencyname = "Coins"
local gamepassId = 14144444

	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,gamepassId) then
	while true do
	wait(timedelay)
			player.leaderstats[currencyname].Value = player.leaderstats[currencyname].Value + amount*2 
			end
	else
		while true do
		wait(timedelay)
		player.leaderstats[currencyname].Value = player.leaderstats[currencyname].Value + amount
		end
	end
end)

Thank you,

1 answer

✓ Accepted answer

Here is a fix, simply add the gamepass check inside the while loop. Fixed Script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local amount = 2
local timedelay = 5
local currencyname = "Coins"
local gamepassId = 14144444

Players.PlayerAdded:Connect(function(Player)
	while wait(timedelay) do
		if Player and Player.Parent then
			local leaderstats = Player:FindFirstChild("leaderstats")
			if leaderstats then
				local Currency = leaderstats:FindFirstChild(Currency)
				if Currency then
					if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,gamepassId) then
						Currency.Value += amount*2
					else
						Currency.Value += amount
					end
				end
			end
		else
			break
		end
	end
end)

Reasons for Changes I made: You assigned a variable to MarketplaceService but didnt seem to use it, i use it here Players is also a service, assigned a variable to it too removed second while loop as

2 comments

0

Worked, Thanks alot!

0

happy to help

This discussion is preserved as it was. New answers, comments, and votes are closed.