This Has Got Me So Confused Now, Ive been trying to make a datastore for points for a while but nothing works, tutorials nope, trying it in studio and out of studio had no use, api services on also and nothing still works. Ive followed so much and spent hours writing code that doesnt work
This is my leaderstats
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = plr
local points = Instance.new("NumberValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
local wins = Instance.new("NumberValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
end)
I Have Some Code I Have Written before hand that was scrapped but it could be close to whats needed so im going to send it below
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“MyDataStore”)
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = plr
local points = Instance.new("NumberValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
local wins = Instance.new("NumberValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
local data
local success, errorMessage = pcall(function()
data = myDataStore:GetAsync(player.UserId)
end)
if success then
Points.Value = data
else
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMessage = pcall(function()
myDataStore:SetAsync(player.UserId, player.leaderstats.Points.Value)
end)
if success then
print("Data Saved")
else
warn(errorMessage)
end
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetChildren()) do
player:Kick(“Server Closed”)
end
wait(2)
end)