Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Special Area Gamepass not working?

Asked by 4 years ago

Hello, I'm trying to make an island you need a gamepass to access. When I test it, someone without the gamepass is allowed to pass through. Here is the code.

local Gamepass = 9281869
local Market = game:GetService('MarketplaceService')
part = script.Parent

game.Players.ChildAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        if Market:UserOwnsGamePassAsync(player.UserId, Gamepass)then
            part.CanCollide = false
        else
                part.CanCollide = true

        end
    end)
end)


0
It should be a local script or else the canCollide will change on the server. If you don't know how roblox's servers and clients work here is something you can read: https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model kingblaze_1000 359 — 4y
0
Basically, when something happens on a server, it happens to every single client in the server. kingblaze_1000 359 — 4y
0
If I make it a local script nothing works? CaptainStevones123 12 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
local id = 9281869
local part = script.Parent

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and ido == id then
        part.CanCollide = false
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
            part.CanCollide = false

        end
    end)
end)
0
i think thats the answer AmIOriginalOrNot 105 — 4y
0
forgot to define part (FIXED) AmIOriginalOrNot 105 — 4y
0
without the first part the part would still be solid and players would have to rejoin for it to work, with those lines it becomes non solid directly when purchasing AmIOriginalOrNot 105 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
--//Variables
local id = 9281869
local part = script.Parent

--//Services
local market = game:GetService("MarketPlaceService")

local function changeState()
    part.CanCollide = false
end

game.Players.PlayerAdded:Connect(function(plr)
    if market:UserOwnsGamePassAsync(plr.UserId, id) or market:PromptGamePassPurchaseFinished(plr, passId, ifPurchased) and ifPurchased and passId == id then
        changeState()
    end
end)

Answer this question