How do you make a tool shop Gui with dataStore?

  1. What do you want to achieve? I want to make a working shop GUI that when players buy an item, they can’t buy more or spam buy them. I also want to add datastore on the shop so if the player rejoins, he/she will get the items back. I already have a leaderstat.

  2. What is the issue? I have followed many tutorials on youtube, but none of them worked.

By the way, I don’t know where to post this, I’m fairly new to the DevForum.

How are you testing it?

Are you testing on Roblox or Roblox Studio?

1 Like

Both, actually. and still doesnt work

Is there any error when testing it on the developer console?

If no then you would ahve to wait for the next developer to come by.

No, nothing shows up, which is weird.

Do you have HTTP requests turned on?

Can you post the code that isn’t working?

Have you tried debugging?

Sorry late reply, yes, http requests are on.

Here’s the script (I followed @Alvin_Blox tutorial) :

local DataStore = game:GetService(“DataStoreService”):GetDataStore(“MyDataStore”)

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

local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = plr

local Bucks = Instance.new("IntValue")
Bucks.Name = "Bucks"
Bucks.Value = 500
Bucks.Parent = folder

local data 
local BucksStored


local success, errorMessage = pcall(function()
	data = DataStore:GetAsync(plr.UserId.."tools")
	BucksStored = DataStore:GetAsync(plr.UserId.."Bucks")
end)

if BucksStored ~= nil then
	Bucks.Value = BucksStored 
else
	Bucks.Value = 5000
end

if data ~= nil then
	for _, toolName in pairs(data) do
		
		local tool = game.ReplicatedStorage.Tools:FindFirstChild(toolName)
		
		if tool then
			local newTool = tool:Clone()
			newTool.Parent = plr.Backpack
			
			local newTool = tool:Clone()
			newTool.Parent = plr.StarterGear
		end
	end
end

end)

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

local toolsTable = {}

for _, tool in pairs(plr.Backpack:GetChildren()) do
	if game.ReplicatedStorage.Tools:FindFirstChild(tool.Name) then
		table.insert(toolsTable,tool.Name)
	end
end

local success, errorMessage = pcall(function()
	DataStore:GetAsync(plr.UserId.."tools",toolsTable)
	DataStore:GetAsync(plr.UserId.."Bucks",plr.leaderstats.Bucks.Value)
end)

end)

game:BindToClose(function()
for _, plr in pairs(game.Players:GetPlayers()) do
local toolsTable = {}

		for _, tool in pairs(plr.Backpack:GetChildren()) do
			if game.ReplicatedStorage.Tools:FindFirstChild(tool.Name) then
				table.insert(toolsTable,tool.Name)
			end
		end

		local success, errorMessage = pcall(function()
			DataStore:GetAsync(plr.UserId, toolsTable)
	end)
end

end)

(The code seems messed up here when posted) The code is all in one script, it just looks weird on the forum.

Your code looks alright. Could be more organized but that’s not the main concern right now.

Are API services are on?

Also are you testing in the Roblox Player or Roblox Studio?

API services are also on. Then, I tested it on the roblox player and on studio, still won’t work.

And you said there is nothing in the dev console, right?

Yes, there are no errors showing up on the dev console.

Hmm. I’m not too sure. DataStores can get complicated quite easily.

It’s also really late at night and I’m kinda tired so there may be an obvious issue that I am overseeing.

Alright, I’ll go check my script again and see if it has any errors. Thanks for answering though.

No problem. If it’s not solved by tomorrow sometime. I’ll dig deeper and try my best to diagnose the issue.

2 Likes

What about your other scripts that give the player the to on the server?

By the way, don’t use the backpack to check what the player has, use StarterGear.

try doing the print thing where you put prints everywhere and if it doesnt print for ex:
it printed on line 1 and others but stopped at line 6
meaning the problem is at line 6!

no thats a bad way… so there is a diff in BackPack and StarterGear, in BackPack when u reset tools wont save… but in starter gear its the opposite… when you try to use the tool you wont see it but why? cuz its in the StarterGear and not in the BackPack

You are doing DataStore:GetAsync While trying to save thats wrong , you gotta do
DataStore:SetAsync(Key,Value)

EDIT : In your case it will be

local success, errorMessage = pcall(function()
	DataStore:SetAsync(plr.UserId.."tools",toolsTable)
	DataStore:SetAsync(plr.UserId.."Bucks",plr.leaderstats.Bucks.Value)
end)
1 Like

ahhh! that’s what was odd… anyways as said in the DataStore page of roblox it has two things that should be put in the bracket i see u everywhere my man

1 Like