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