I need help creating a simple gamepass script. I have tried several tutorials and they’re either outdated or not what I am looking for.
I already have a script that makes it so when you click a button, you’re prompted to buy the speed coil. I need help with a script that would actually automatically give the player in-game the speed coil, when they have the gamepass.
local player = game.Players.LocalPlayer
local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,8222423)
if ownsGamepass then
local sword = game:GetService("ReplicatedStorage"):WaitForChild("SpeedCoil"):Clone()
sword.Parent = player.Backpack
end
This is what it should look like if you’re giving tools to the player via gamepasses;
local MarketPlaceService = game:GetService("MarketplaceService") -- Get's the service so we can make the gamepass
local GamepassID = 00000-- The Gamepass ID
game.Players.PlayerAdded:Connect(function(player)
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then -- Checking if the player owns the gamepass
game.ServerStorage.SpeedCoil:Clone().Parent = player:WaitForChild("Backpack") -- Putting the tool into the players backpack
game.ServerStorage.SpeedCoil:Clone().Parent = player:WaitForChild("StarterGear") -- Finding the tool from ServerStorage
end
end)
local plr = game.Players.LocalPlayer
local button = script.Parent
local MarketplaceService = game:GetService("MarketplaceService")
script.Parent.MouseButton1Click:Connect(function()
MarketplaceService:PromptGamePassPurchase(plr, 0) -- Your gamePass Id Here
end)