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
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)
local id =
if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,id) then
-- function
end