Datastore wont work

Yes, the datastore is a free model

-- This is a 5-way script. Thanks for using it!


function onPlayerEntered(player)
wait()-- Change to wait for player longer.
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait()
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren()
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

that’s the datastore, my games stats are called “Time”
and “Rebirths”
when u rejoin you dont keep your time

the stats script is this

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player

local points = Instance.new("IntValue")
points.Name = "Time"
points.Value = 0
points.Parent = leaderstats

local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Value = 0

rebirths.Parent = leaderstats

info that you might need to help me
the datastore is in workspace,
the stats script is in server script service

I’m not sure why your using this at all, because it looks old and it isn’t even using functions that aren’t deprecated, deprecated functions and instances usually have issues or have been preceded by another instance/function.

There’s a really simple data store tutorial on the new and old Roblox API Website, I’m not sure why you just won’t use that instead, as its more updated then outdated.

Those functions look outdated

Try using this in ServerScriptService:

local players = game:GetService("Players")
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("Time")
local ds2 = datastore:GetDataStore("Rebirths")

players.PlayerAdded:connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "leaderstats"
	folder.Parent = player

	local currency1 = Instance.new("IntValue")
	currency1.Name = "Time"
	currency1.Parent = player.leaderstats
	currency1.Value = ds1:GetAsync(player.UserId) or 0
	ds1:SetAsync(player.UserId, currency1.Value)

	local currency2 = Instance.new("IntValue")
	currency2.Name = "Rebirths"
	currency2.Parent = player.leaderstats
	currency2.Value = ds2:GetAsync(player.UserId) or 0
	ds2:SetAsync(player.UserId, currency2.Value)

--updates the leaderboard on joining
	currency1.Value = currency1.Value + 1
	currency2.Value = currency2.Value + 1
	wait()
	currency1.Value = currency1.Value - 1
	currency2.Value = currency2.Value - 1

--autosave
	while true do
		wait(15)
		ds1:SetAsync(player.UserId, currency1.Value)
		ds2:SetAsync(player.UserId, currency2.Value)
	end end)
1 Like

I cant really write any code exampels atm. Ill just leave this short message instead. This script uses the outdated system" Data Persistence". It was disabled last year. Switch to Data Stores instead.

Again i would have added some code here but since im in a lil bit of a rush i cant write that much. If youre a beginner to data stores or coding in general id recommend you watch this: Roblox DataStore Tutorial - Data Stores & Saving Data - Scripting Tutorial - YouTube