Error with local script

Does anyone know why this script isn’t working?

local ms = game:GetService("MarketplaceService")

local function userOwnsPass(player)
	if ms:UserOwnsGamePassAsync(player.UserId, 14886726) then
		return true
	else
		return false
	end
end

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local isAble = userOwnsPass(game.Players.LocalPlayer)
		
		if isAble then
			script.Parent.CanCollide = false
		else
			ms:PromptGamePassPurchase(game.Players.LocalPlayer, 14886726)
		end
	end
end)
1 Like

What do you mean by “isn’t working”? Were there any errors or did it just not do what you wanted it to?

1 Like
  1. Use a normal Script and not a LocalScript

  2. Put this code in.

local ms = game:GetService("MarketplaceService")

local function userOwnsPass(player)
    if ms:UserOwnsGamePassAsync(player.UserId, 14886726) then
        return true
    else
        return false
    end
end

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        
        if player then
            local isAble = userOwnsPass(player)
        
            if isAble then
                script.Parent.CanCollide = false
            else
                ms:PromptGamePassPurchase(player, 14886726)
            end
        end
    end
end)
2 Likes