This data store is suppose to save Items that are put directly into your startergear in game. But it isn't working. And I do not know why.
Here is the script:
local key = 'weps'
local exclude = {
'GameMusicHuman, GameMusicInfected, LobbyMusic, CamControl, NoNames, ToggleFlashlight, ToggleSound';
}
game.Players.PlayerAdded:connect(
function(p)
local weps = data:GetAsync(p.userId..'_'..key)
if weps then
for _,v in pairs(weps) do
if game.ReplicatedStorage:FindFirstChild(v) then
game.ReplicatedStorage[v]:clone().Parent = p.StarterGear
end
end
end
p.StarterGear.ChildAdded:connect(
function(c)
local tools = { }
for _,v in pairs(p.StarterGear:GetChildren()) do
local add = true
for _,c in pairs(exclude) do
if v.Name ~= c.Name then
add = false
end
end
if add then
table.insert(mo, v.Name)
end
end
data:SetAsync((p.userId..'_'..key), tools)
end
)
end
)
Would this help?
local store = game:GetService("DataStoreService"):GetDataStore("data")
local http = game:GetService("HttpService")
local Convert = function(data)
if type(data) == "string" then
if pcall(function() http:Decode(data) end) then
return http:Decode(data)
else
return data
end
elseif type(data) == "table" then
return http:ncode(data)
elseif type(data) ~= "userdata" and type(data) ~= "thread" then
return data
else
return nil,warn("Cannot convert "..type(data))
end
end
local a = {
save = function(self,key,value)
if key then
if type(key) == "string" then
if value then
local value = Convert(value)
if value ~= nil then
if store:GetAsync(key) then
store:UpdateAsync(key,function(old) return value end)
return store:GetAsync(key)
else
store:SetAsync(key,value)
return store:GetAsync(key)
end
end
else
if store:GetAsync(key) then
return Convert(store:GetAsync(key)), warn("No value given to save")
else
return nil,warn("No value given to save")
end
end
else
return nil, warn(key.." is an invalid key")
end
else
return nil,warn("No key given")
end
end;
load = function(self,key)
if key then
if type(key) == "string" then
if store:GetAsync(key) then
return Convert(store:GetAsync(key))
else
return nil
end
else
return nil, warn(key.." is an invalid key")
end
else
return nil,warn("No key given")
end
end;
setStore = function(self,name)
if name and type(name) == "string" then
store = game:GetService("DataStoreService"):GetDataStore(name)
end
end
}
return a

2 comments
I dont believe Datastore works with tables, so I would use a string then after you GetAsync you can convert it into a table.
Could you possibly show me how to do that... If not thats okay.