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

How can I set up a shop so that you can purchase access to a room?

Hi, I'm currently learning how to code things like a shop, and I was wondering how I could set it up that I would be able to host a shop. Players would buy access to the room once from an NPC, and they would be able to access the room for as long as the data is saved.

How could I possibly set this up? Thanks in advance!

2 answers

Lets assume you're using a simple ID-based gui shop. In the server storage, you want a folder called "Player Objects", and put a bool value named "room1" in that folder. Make sure the value of the bool value is set to false.

Next, make a script in server script service called "ObjectInsertation" and have it say something like this:

game.Players.PlayerAdded:connect(function(player)
	local object = game.ServerStorage.room1:Clone()
	object.Parent = player
end)

After that, in your shop have something like this on the purchase:

local player = script:FindFirstAncestorWhichIsA("player") 
--Cut this out if the player is already defined
player.room1.Value = true
--Add the rest of whatever else is in your shop here

Next, insert this into your door:


script.Parent.Touched:Connect(function(hit)
	local player = hit:FindFirstAncestorWhichIsA("Model")
	local PPlayer = game.Players:FindFirstChild(player.Name)
	
	if PPlayer.room1.Value == true then
		--Do nothing. Make sure the doors collision is off.
		else
		player.Humanoid.Health = 0
	end)

end)

And thats it!

3 comments

0

Thanks! But will this save if the player leaves?

0

That depends on if its a gamepass or a dev product

0

This would be designed for a currency shop; for a gamepass you would do something very different, and for a non-gamepass you need to set up a datastore script.

You could make two teams and then look at this: developer.roblox.com and after the players buys the product, they switch to the team that goes through the door.

1 comment

0

that link is to "how to make a team only door"

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