--[[
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)
Not sure why this wouldn’t throw an error, as MarketplaceService is spelled incorrectly
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
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.