#How to make it so players cant buy the same item after they leave and join
1 messages · Page 1 of 1 (latest)
Your best option here is to use DataStoreService. It’s the easiest way to save data. All you’ll really need to do is create a table that save a boolean that dictates whether or not the player has already bought the item, and save that boolean/upload it again when they rejoin. You can then check this boolean to see if the player owns the item later when they go to buy it.
i already am using a datastore service
local DataStoreService = game:GetService("DataStoreService")
local shovelStore = DataStoreService:GetDataStore("ShovelPurchases")
game.Players.PlayerAdded:Connect(function(player)
local userId = tostring(player.UserId)
local data
local success, err = pcall(function()
data = shovelStore:GetAsync(userId)
end)
if not success then
warn("Failed to load data:", err)
return
end
-- Create a default if no data
if not data then
data = {
hasRusty = false,
hasBasic = false,
hasIron = false,
}
end
-- Store in player for session
local folder = Instance.new("Folder")
folder.Name = "ShovelData"
folder.Parent = player
for k, v in pairs(data) do
local boolVal = Instance.new("BoolValue")
boolVal.Name = k
boolVal.Value = v
boolVal.Parent = folder
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local userId = tostring(player.UserId)
local folder = player:FindFirstChild("ShovelData")
if folder then
local data = {}
for _, child in ipairs(folder:GetChildren()) do
data[child.Name] = child.Value
end
pcall(function()
shovelStore:SetAsync(userId, data)
end)
end
end)
Oh I see, sorry I missed that initially.
Are you simply not seeing your data load? Or is there an error message printing?
I would strongly suggest rereading it to find the issue because I and other people like myself don't really feel like reading allat
no no the data is loading its just that whenever you join back you can buy the item in the shop that is free when I only want the player to have 1
and im just wondering how i could do that