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

Make this script Gamepass activated?

I want to make this function in my script only run for a player if they have a Gamepass.

local player = script.Parent
local trail = game.ReplicatedStorage.TrailMachine

function createMachine()
	local trailClone = trail:Clone()
	trailClone.PrimaryPart = trailClone.Core
	trailClone.Parent = player
	trailClone:moveTo(player.Torso.Position)
	
	local weld = Instance.new("Motor6D")
	weld.Parent = trailClone.Core
	weld.Part0 = trailClone.Core
	weld.Part1 = player.Torso
end

Any help would be appreciated

2 answers

✓ Accepted answer

Use the PlayerAdded event and check if they have a certain gamepass using the method UserOwnsGamePassAsync.


local trail = game.ReplicatedStorage.TrailMachine
mps= game:GetService("MarketPlaceService")
function createMachine()
    local trailClone = trail:Clone()
    trailClone.PrimaryPart = trailClone.Core
    trailClone.Parent = player
    trailClone:moveTo(player.Torso.Position)

    local weld = Instance.new("Motor6D")
    weld.Parent = trailClone.Core
    weld.Part0 = trailClone.Core
    weld.Part1 = player.Torso
end
game:GetService("Players").PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player.UserId,passID) then
		createMachine(player)
	end
end)

1 comment

0

I replaced "passID" with the gamepass id, but the function still isn't running.

local id =

if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,id) then

-- function

end

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