How would I go about making an area gate like in simulators?

I want to have an area gate, like in simulators, where when you buy it, its permanently gone for that player.

I just don’t know how to even go about doing this, and google didn’t really help.

I already have the gate itself and the buying function, and it only goes away locally, I just don’t know how to store the info of it being gone for a certain player.

1 Like

Assuming you want it to be unlocked by purchasing a gamepass then you’d first have to create a gamepass, get its id and have the ability to purchase it somewhere in the game using

game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamepass)

then inside the part that is blocking off an area you could do

local part = script.Parent
local gamePassId =

local MPS = game:GetService("MarketplaceService")

part.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:FindFirstChild(hit.Parent.Name)
		if MPS:UserOwnsGamePassAsync(plr.UserId, gamepass) then
		else
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(100)
		end
	end
end)

Otherwise if its not a gamepass you would have to use datastores to store some sort of value, a bool would work that is set to true when the player buys the item. Then you could adapt the second script to instead check if that bool value is set to true. I can make a script for datastores too but unless that’s what you need I don’t want to waste time adapting an older datastore script of mine to work for you. If you need it tho I’ll make it

on and also to make it appear like the gate is gone you can do a local script on the client that sets the part transparency to one if the player owns the gamepass or has the bool value set to true in their datastore.

If you could give me an example of how to set it up for it not being a gamepass, that would be great! I don’t need you to make the script, that way i can learn.

You can search documentations and other posts. Ill give you an older datastore I used that you can adapt for yourself.

script:


local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Storage")


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	
	
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Cash = Instance.new("NumberValue")
	
	Cash.Name = "Cash"
	Cash.Value = 5000
	Cash.Parent = leaderstats
	

	local data
	local success, errormessage = pcall(function()
		data = dataStore:GetAsync(player.UserId.."Cash")
	
	end)

	
	if success then
		
		Cash.Value = data
	else
		print("There was an error.")
	
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)

	local success, errormessage = pcall(function()
		dataStore:SetAsync(plr.UserId.."Cash", plr.leaderstats.Cash.Value)
	end)

	if success then
		print("Successfully saved Player Data!")
		
	else
		print("There was an error while saving player data!")
		warn(errormessage)
	end
end)

Store a boolean in a datastore and set it to true whenever the player buys the area