Data Store help

I need a data store to save a booth using a proximity prompt and a game pass purchased. I want the booth to load for the player the next time they enter the game.

I’m not very good with datastores. I have them working for leader stats but when it comes to trying to incorporate it outside of leader stats I’m not doing too good.

I have researched here on the forums for information to help and I’ve practiced and tried different ways to no avail yet.

I do have a booth currently that can be obtained via the proximity prompt. I learned this watching a you tube tutorial. I want to add the game pass into the prompt, where the player has to have the game pass at the time of the prompt trigger, in order to get the booth. My proximity prompt function looks at the remote event value with an if statement. So I thought that I could include something in the if statement, but I’ve not been able to get this to work yet.

Then with the data store, I was trying to have the booth entered into the players newly created inventory folder to save it so upon re entry the booth is still theirs to be loaded. Upon player adding it loads a clone of the booth, upon removing it adds it to the inventory folder. I tried this using the proximity prompt as well but could not get it to work.

I think my issue is in how i structure and write the code out b/c I do understand what I am trying to accomplish.

Any suggestions ?

My Code for data store

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local dataservice = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
local inventorydata = dataservice:GetDataStore("player_data")
local booth = game.Workspace:GetChildren("Booth")
local prox = game.Workspace.Booth.Prompt.ProximityPrompt
local pp = game.Workspace.Booth.Prompt:WaitForChild("ProximityPrompt")
inv = {}

game.Players.PlayerAdded:Connect(function(player)
	local inventory = Instance.new("Folder")
	inventory.Name = "inventory"
	inventory.Parent = player
	pp.Triggered:Connect(function(player)
		--print("triggered")
		--prox.Enabled = true
	--if proxprompt.Enabled == true then
		--if prox.Enabled == true then
			table.insert(inv, booth)
			print("booth")
		--end			
	--end
	end)	
	local inv = inventorydata:GetAsync(player.UserId) or {}	
	for i, v in pairs(player.inventory:GetChildren(booth)) do
		local booth = inventory:Clone()		
	end
end)

game.Players.PlayerRemoving:Connect(function(player)	
	local inv = {}		
	for i, v in pairs(player.inventory:GetChildren(inv)) do
		table.insert(inv,player.booth)
	end
end)

My code for Booth, Proximity Prompt

local prox = script.Parent
local boothModel = prox.Parent.Parent
local topSign = boothModel.TopSign
local BottomPart = boothModel.BottomPart
local claimedBoothRemote = game.ReplicatedStorage.ClaimedBooth
local editBoothRemote = game.ReplicatedStorage.EditBooth

prox.Triggered:Connect(function(plr)	
	local claimedBooth = plr.ClaimedBooth	
	if claimedBooth.Value == nil then		
		prox.Enabled = false
		claimedBooth.Value = boothModel		
		BottomPart.SurfaceGui.PlayerName.Text = plr.Name.. "'s Booth"
		topSign.SurfaceGui.ImageLabel.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)		
		claimedBoothRemote:FireClient(plr, boothModel)		
	elseif claimedBooth.Value == boothModel then		
		editBoothRemote:FireClient(plr)				
	end	
end)

My Booth proximity prompt setup
booth setup
My remote Vent in Replicated Storage
claimed booth remote event
My Inventory folder when the game is started sitting under Players
inventory folder

I don’t understand your problem, can you explain more precisely where your problem is?
Do we just need to find the right “booth” storage method?

Yes I believe so. I can seem to figure out the right way to do it or write it in the script.

To implement the functionality you described, you will need to modify the existing code to incorporate data stores and game passes.

First, you need to check if the player has purchased the game pass before allowing them to claim the booth. To do this, you can add the following code inside the prox.Triggered function:

if game:GetService("GamePassService"):PlayerHasPass(plr, YOUR_GAME_PASS_ID) then
    -- allow the player to claim the booth
else
    -- tell the player they need to purchase the game pass to claim the booth
end

Replace YOUR_GAME_PASS_ID with the actual game pass ID.

Next, to save the claimed booth in a data store, you can use the player’s unique UserId as the key and store the booth’s Name as the value. Here’s an example of how you can modify the prox.Triggered function to save the booth:

prox.Triggered:Connect(function(plr)    
    local claimedBooth = plr.ClaimedBooth    
    if claimedBooth.Value == nil then
        if game:GetService("GamePassService"):PlayerHasPass(plr, YOUR_GAME_PASS_ID) then
            -- allow the player to claim the booth
            prox.Enabled = false
            claimedBooth.Value = boothModel        
            BottomPart.SurfaceGui.PlayerName.Text = plr.Name.. "'s Booth"
            topSign.SurfaceGui.ImageLabel.Image = game.Players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)       
            claimedBoothRemote:FireClient(plr, boothModel)

            -- save the booth in the data store
            local success, err = pcall(function()
                inventorydata:SetAsync(plr.UserId, boothModel.Name)
            end)
            if not success then
                warn("Failed to save booth in data store:", err)
            end
        else
            -- tell the player they need to purchase the game pass to claim the booth
            -- you can use a TextLabel or a MessageDialog to display this message
        end
    elseif claimedBooth.Value == boothModel then
        editBoothRemote:FireClient(plr)               
    end 
end)

In the code above, pcall is used to catch any errors that may occur when saving the booth in the data store. If an error occurs, it will be printed to the console.

To load the player’s claimed booth when they re-enter the game, you can use the inventorydata:GetAsync function to retrieve the booth’s name from the data store and then find it in the workspace using Workspace:FindFirstChild . Here’s an example of how you can modify the game.Players.PlayerAdded function to load the booth:

game.Players.PlayerAdded:Connect(function(player)
    local inventory = Instance.new("Folder")
    inventory.Name = "inventory"
    inventory.Parent = player

    -- load the player's claimed booth from the data store
    local success, claimedBoothName = pcall(function()
        return inventorydata:GetAsync(player.UserId)
    end)
    if success and claimedBoothName then
        local claimedBooth = game.Workspace:FindFirstChild(claimedBoothName)
        if claimedBooth then
            player.ClaimedBooth.Value = claimedBooth
            claimedBoothRemote:FireClient(player, claimedBooth)
        end
    end
end)

In the code above, pcall is used again to catch any errors that may occur when retrieving the claimed booth name from the data store. If an error occurs or the player doesn

I do have the pass code script already working as a purchase using a gui (see below- i suppose i didn’t mention that part before), but when I went to incorporate it into the proximity prompt code and data store I was having issues. I am going to look at what you’ve posted and mess with my script more, I will report back with my success.

Thanks for the input and help.

game pass script
‘’’
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local boothGamepassID = 140826673

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, boothGamepassID)
end)
if hasPass then
print(“player has the gamepass”)
–local booth = game.ReplicatedStorage.booth:Clone()
–booth.Parent = player.Backpack
end
end)
end)

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
if purchaseSuccess == true and purchasedPassID == boothGamepassID then
print(player.Name…“purchased the game pass!”)
–local booth = game.ReplicatedStorage.booth:Clone()
–booth.Parent = player.Backpack
end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
‘’’

I have not gotten it to work yet. I am a bit confused after looking at your recommendations.

We did not incorporate the inventory folder at all. The folder gets created but nothing is moving into it. So in what you’ve recommended we just aren’t using it at all anymore. I guess I was thinking this would be the way to get the booth to save and then load after it was saved in the data store.

In your suggestion, it appears my if statement in regards to the Proximity Prompt goes into my proximity prompt scripts which actually sit in game.workspace inside the proximity prompt of the booth, it is not on the server script service in the data store script, yet it has data store SetAsync in it ? I have a lot of Booth’s and each one has its own proximity prompt script. Also, Will this cause an issue if I have only one remote event for all of the booths ?

My data store script is in server script service.

So in this scenario the SetAsync script portion sits in a script in the proximity prompt of the booth in workspace. but my GetAsync data store script sits in server script service. The two don’t seem to tie in together.

On the SetAsync side we are referencing boothModel.Name
On the GetAsync side we are referencing claimedBoothName

I think this is all get twisted in my mind. Uugghh

Then you have a section in the data store script which addresses when the player is added into the game.

The two don’t appear to be tying together to make this happen.

I have found a different solution for this all the way around because I did not get it to work as originally intended. My work around solution does work just differently than I was thinking this through.