What do you want to achieve? I am trying to make a saving index with values
What is the issue? Whenever I try saving the value it does nothing and loading prints nil in the output.
What solutions have you tried so far? I tried changing the string value to a int value and adding prints to see where it’s not working.
While I was writing this I saw “Id-(My userid)” in the output but couldn’t make it do that again.
Output:
![]()
Script:
local datastore = game:GetService("DataStoreService"):GetDataStore("Littes")
game.Players.PlayerAdded:Connect(function(player)
local key = "id"..player.userId
local littes = Instance.new("Folder",player)
littes.Name = "Littes"
pcall(function()
local littes = datastore:GetAsync(key)
print(littes)
if littes then
for i,v in pairs(littes) do
print(v)
local litte = Instance.new("IntValue",littes)
litte.Value = v
litte.Name = v
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = "id-"..player.userId
local folder = player:WaitForChild("Littes")
pcall(function()
local littes = {}
for i, v in pairs(folder:GetChildren()) do
if v then
table.insert(littes,v.Value)
print("saving" .. littes)
end
end
datastore:SetAsync(key,littes)
print(key)
end)
end)
for i, v in pairs(workspace.Littes:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local folder = player:WaitForChild("Littes")
if folder:FindFirstChild(v.Name) then
--
else
local value = Instance.new("IntValue",folder)
value.Value = v.Name
value.Name = v.Name
game.ReplicatedStorage.Remotes.LitteSound:FireClient(player)
end
end
end)
end
end