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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

0
Thanks! But will this save if the player leaves? DaRealFM2 0 — 3y
0
That depends on if its a gamepass or a dev product super00rocket 27 — 3y
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. APaperDeveloper 3 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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.

0
that link is to "how to make a team only door" super00rocket 27 — 3y

Answer this question