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

making a tool only accessible to players who bought the gamepass?

so this is the code

local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(plr)
	local success, message = pcall(function()
		local haspass = false
		local gamepassID = 9794050
		haspass = MarketPlaceService:UserOwnsGamePassAsync(plr.UserId, gamepassID)
		if haspass == true then
			local gravitycoil = plr.Backpack.GravityCoil 
			gravitycoil.Enabled = true
		end
	end)
end)

so there is a tool in starter pack and it is a gravity coil this code makes it so the coil is enabled if they bought the gamepass the gravitycoil.enable = true runs so idk if enabled works i read that it makes it unusable if it is false and i have it automatically set to false so could you tell me if im doing something wrong or a different way to do it like .activation or something like that?

1 comment

0

check studioplus.io

1 answer

✓ Accepted answer

Hope this helps, there are many ways on making gamepass scripts but, i just find this more suitable and does work.

local id = 0  --gamepass id
local t2 = game.ServerStorage.toolName
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and ido == id then
	plr.CharacterAdded:connect(function(char) 
     t2.Parent = plr.StarterGear
     t2:Clone().Parent = plr.Backpack  
end)
    end
end)
 
game.Players.PlayerAdded:Connect(function(plr)   
    plr.CharacterAdded:connect(function(char)
 if  game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
         t2.Parent = plr.StarterGear
     t2:Clone().Parent = plr.Backpack  
        end
    end)
end)

also make sure that if above game is next to game.

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