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!
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!
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.