Gamepass Script not working

My script is not working for a gamepass. It’s a local script in StarterGUI.

``local MarketPlaceService = game:GetService(“MarketplaceService”)

local GamepassId = 19867734

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
print(“GamePass Owned”)
else
local RotationSpeed = 0
game[“Run Service”].RenderStepped:connect(function()
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(0,math.rad(RotationSpeed),9.5)
end)
end
end)
end)``

1 Like

What is this gamepass do if you purchase it?

The gamepass flips the camera over. the script makes the camera upside down

--[[
  I suggest that you should write your script in an efficient way
to make it easier to read.
]]

-- Services
local RunService = game:GetService("RunService")
local MarketPlaceService = game:GetService("MarketPlaceService")
local Players = game:GetService("Players")

local GamepassID = 19867734

Players.PlayerAdded:Connect(function(thisPlayer)
    thisPlayer.CharacterAdded:Connect(function(Character)
        if MarketPlaceService:UserOwnsGamePassAsync(thisPlayer.UserID, GamepassID) then
            print(thisPlayer.Name, "owns the gamepass.")
        else
            local RotationSpeed = 0
            RunService.RenderStepped:Connect(function()
                workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(0,math.rad(RotationSpeed),9.5)
            end)
        end
    end)
end)

Is this a Script or a LocalScript?

Local script, in StarterGUI (I need characters)

Do you get any errors? or warnings?

No Sir. Even with your script to errors or warnings.

What about the outputs? does the camera rotates if you dont own the gamepass?

No outputs either, nothing is happening

try adding print("I guess not") inside the else condition (before the RotationSpeed) lets see if it outputs.

Not sure why this wouldn’t throw an error, as MarketplaceService is spelled incorrectly :x:

Is the script running at all?

Also, this way of listening to the PlayerAdded event without checking if the player argument is the same as the local player will cause your client to perform this check for everyone. Instead, say this

local player = game.Players.LocalPlayer
player.CharacterAdded:connect(function(character)
-- code
end)

I also advise against checking the MarketplaceService every time the character respawns to see if they own the asset or not, it would be better instead check when they join the game, and when they purchase the asset.

EDIT: If you have to parent scripts to a local directory I would choose the StarterPlayerScripts folder, as it was intended for this purpose :grinning_face_with_smiling_eyes:

1 Like

the script isn’t running at all, the prints aren’t printing and nothing seems to work

Where does this go? sorry lol :frowning:

In my conclusion, using PlayerAdded function is not necessary here because the localscript will run once the player loads. we just need to wait for the character to spawn.

local RunService = game:GetService("RunService")
local MarketplaceService = game:GetService("MarketplaceSerice")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local GamepassID = 123456789 -- Change this
local isAllowed = false

-- As @SoyBeen suggested that it should be checked once the player only joins the game. (I haven't added a script of when a player buys the gamepass inside the game. I forgot how to add it.)
if MarketplaceService:UserOwnsGamepassAsync(LocalPlayer.UserId, GamepassID) then
   isAllowed = true 
end

-- Run as function
local function adjustCamera()
    if isAllowed == true then
        print("FOO")
    elseif isAllowed == false then
        print("BAR")
        local RotationSpeed = 0
        RunService.RenderStepped:Connect(function()
            workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(0,math.rad(RotationSpeed),9.5)
        end)
    else
        warn("Something went wrong.")
    end
end


LocalPlayer.CharacterAdded:Connect(function(Character)
    local Humanoid = Character:FindFirstChild("Humanoid")
    
    if Humanoid then
       adjustCamera() 
    end
end)




I think instead of making it a complicated script , you can just write this code -
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(player.UserId,gamepass id) then
[just write the code here by which the benefit you want to give from the game pass]
end

I used this code to clone an extra weapon which can be given to the player only on the purchase of the gamepass.

Is the script itself disabled? Can you print at the very first line of the script?

If neither, can you screenshot where this script lives inside your hierarchy?

When a script isn’t running at all, usually you’ve just parented it to a directory where it’s not allowed to run.