I made a datastore but it won’t work, i tried to fix it for days now, but i failed,
here is the code:
local dss = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local Data = dss:GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(p)
local Leaderstats = Instance.new("Folder", p)
Leaderstats.Name = "leaderstats"
local gold = Instance.new("IntValue", Leaderstats)
gold.Name = "Gold"
local data
local success, err = pcall(function()
data = Data:GetAsync(p.UserId..'-gold')
end)
if success then
gold.Value = data
else
print("oops! could not load your data:(")
warn(err)
end
--p.CharacterAdded:Connect(function()
-- p.Character.Humanoid.Died:Connect(function() [[ FOR FORUMS ]]
-- p.Team = game.Teams.spectator
-- end)
--end)
end)
game.Players.PlayerRemoving:Connect(function(p)
local success, err2 = pcall(function()
Data:SetAsync(p.UserId..'-Gold',p.leaderstats.gold.Value)
end)
if success then
print("stats saved successfully!")
else
print("oops! could not save your data:(")
warn(err2)
end
end)