You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I have a CollectionService with a bunch of Collectible parts with the same name, and when you touch the part it makes it Invisible and you cannot touch it, I want to DataStore this so Collectibles that the player have already Collected cannot be Collected again, and those that hasn’t been Collected can still be Collected.
- What is the issue? Include screenshots / videos if possible!
When I collect one collectible and save and load back in, I can’t collect the collectibles I haven’t collected yet.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked for solutions everywhere and have found nothing.
For clarification, This DataStore has different Save Slots
This is my script:
for i, Collectible in pairs(CS:GetTagged("Collectible")) do
---------GetAsync
event.OnServerEvent:Connect(function(plr, typeOf)
if typeOf == "slot4" then
local success, errormessage = pcall(function()
print("worked")
local data = DataStore:GetAsync(plr.UserId .. "-slot1")
if data ~= nil then
Coins.Value = data[1] ------Ignore
Collectibles.Value = data[2] -----Ignore
Collectible.Transparency = data[3]
Collectible.CanTouch = data[4]
else
Coins.Value = 0
Collectibles.Value = 0
end
end)
if success then
print("success")
end
if errormessage then
warn(errormessage)
end
end
end)
event.OnServerEvent:Connect(function(plr, typeOf)
if typeOf == "slot5" then
local success, errormessage = pcall(function()
print("worked")
local data = DataStore:GetAsync(plr.UserId .. "-slot2")
if data ~= nil then
Coins.Value = data[1]
Collectibles.Value = data[2]
Collectible.Transparency = data[3]
Collectible.CanTouch = data[4]
else
Coins.Value = 0
Collectibles.Value = 0
end
end)
if success then
print("success")
end
if errormessage then
warn(errormessage)
end
end
end)
event.OnServerEvent:Connect(function(plr, typeOf)
if typeOf == "slot6" then
local success,errormessage = pcall(function()
print("worked")
local data = DataStore:GetAsync(plr.UserId .. "-slot3")
if data ~= nil then
Coins.Value = data[1]
Collectibles.Value = data[2]
Collectible.Transparency = data[3]
Collectible.CanTouch = data[4]
else
Coins.Value = 0
Collectibles.Value = 0
end
end)
if success then
print("Success")
end
if errormessage then
warn(errormessage)
end
end
end)
---------SetAsync
Sevent.OnServerEvent:Connect(function(plr)
print("worked")
DataStore:SetAsync(plr.UserId .. "-slot1", {Coins.Value, Collectibles.Value, Collectible.Transparency, Collectible.CanTouch})
end)
Sevent2.OnServerEvent:Connect(function(plr)
print("worked")
DataStore:SetAsync(plr.UserId .. "-slot2", {Coins.Value, Collectibles.Value, Collectible.Transparency, Collectible.CanTouch})
end)
Sevent3.OnServerEvent:Connect(function(plr)
print("worked")
DataStore:SetAsync(plr.UserId .. "-slot3", {Coins.Value, Collectibles.Value, Collectible.Transparency, Collectible.CanTouch})
end)
game:BindToClose(function()
for i, plr in pairs(game.Players:GetPlayers()) do
DataStore:SetAsync(plr.UserId .. "-slot1", {Coins.Value, Collectibles.Value, Collectible.Transparency, Collectible.CanTouch})
end
end)
end
Any help is appreciated