Issue With Script For Gamepass

So I’ve been planning on making a gamepass for my game for a while now, and I’ve finally decided that I wanted to start working on it.

I’m a pretty new scripter so I don’t know a whole lot about how to make a gamepass, and I’ve watched many tutorials but can never find one for what I’m trying to add.

I’m trying to Enable a script that contains the main function for the gamepass but I’m clueless on if I’m doing something wrong, or if you can’t Enable/Disable a script… from another script.


Here’s the code:

local Players = game:GetService("Players")
local id = 254553044

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			print("")
			game.StarterPlayer.StarterPlayerScripts.NightVisionGP.Disabled = false
		end
	end)
end)

Help, is much appreciated.

1 Like
--Script inside StarterCharacterScripts
local MarketplaceService = game:GetService("MarketplaceService")

local character = script.Parent
local player = game.Players:GetPlayerByCharacter(character)

local id = 254553044

local owned = MarketplaceService:UserOwnsGamePassAsync(player.UserId, id)
player.PlayerScripts.NightVisionGP.Enabled = owned

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, gp, purchased)
	if not purchased or gp ~= id or plr ~= player then return end
	player.PlayerScripts.NightVisionGP.Enabled = true
end)
2 Likes

I added the following script to StarterCharacterScripts and it did nothing.

I have no Idea if I’m doing something wrong, or if another script in the game is Interfering with this one…

Thank You for trying though!

1 Like