Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Special Area Gamepass not working?

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)


3 comments

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

0

Basically, when something happens on a server, it happens to every single client in the server.

0

If I make it a local script nothing works?

2 answers

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)

3 comments

0

i think thats the answer

0

forgot to define part (FIXED)

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

--//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)

This discussion is preserved as it was. New answers, comments, and votes are closed.