Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why would my dataStore not load my game data?

I'm not for sure if it's not saving or not loading, due to the fact i have a pcall set up and it runs save successful and loading successful. It's a super simple script, and I have Api services turned on Aswell! I'm new to Datastore services, and I've done research on a ton of datastores setup multiple ways, but none seem to work for me!!

Current leaderstats\DataSaving Script

local player = game:GetService('Players')
local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore("clickData")

player.PlayerAdded:Connect(function(plr)
	print(plr.Name..plr.UserId.." Has Been Added to the Game")
	
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	local clicks = Instance.new("IntValue", leaderstats)
	clicks.Name = "Clicks"
	clicks.Value = 0
	
	local data
	
	local succ, err = pcall(function()
			data = dataStore:GetAsync( "player_"..plr.UserId)
	end)
	
	if succ then
		print("DataLoaded!")
		clicks.Value = data
	else
		print("DataNotSaved")
		warn(err)
	end
	
	
	
	
	
	
end)

player.PlayerRemoving:Connect(function(plr)
	local data 
	
	local succ, err = pcall(function()
			data = dataStore:SetAsync( "player_"..plr.UserId, plr.leaderstats.Clicks.Value)
	end)
	
	if succ then
		print("DataSaved")
	else
		print("SaveFailed")
		warn(err)
	end
end)

Previous Script

local player = game:GetService('Players')
local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore("clickData")

player.PlayerAdded:Connect(function(plr)
	print(plr.Name..plr.UserId.." Has Been Added to the Game")
	
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	local clicks = Instance.new("IntValue", leaderstats)
	clicks.Name = "Clicks"
	clicks.Value = 0
	
	local data
	
	local plrid = plr.UserId
	
	
	
	local succ, err = pcall(function()
		data = dataStore:GetAsync( "player_"..plrid)
	end)
	
	if succ then
		print("DataLoaded!")
		clicks.Value = data
	else
		print("DataNotSaved")
		warn(err)
	end
	
	
	
	
	
	
end)

player.PlayerRemoving:Connect(function(plr)
	local data
	
	local plrid = plr.UserId
	
	local succ, err = pcall(function()
		data = dataStore:SetAsync( "player_"..plrid, plr.leaderstats.Clicks.Value)
	end)
	
	if succ then
		print("DataSaved")
	else
		print("SaveFailed")
		warn(err)
	end
end)

2 comments

0

Does the error print?

0

no error prints, the only thing that prints are data loaded and data save

1 answer

✓ Accepted answer

Change PlrId_fordata to "player_"..plrid idk why but that fixes it

7 comments

0

I redone the script, if i understood what you meant correctly, and it's still not loading my player data. I Put on updated script with what i thought you meant

0

i meant dont do it with a variable it does not work for some reason

0

ive changed it from a variable and it still isnt working, it comes up with no error but doesnt actually load the stats to the leaderboard.

0

thats strange it was working for me did you turn on api services

0

I do have Api services on

0

is this script inside of serverscriptservices

0

it was, but still didnt work, i swapped to DataStore2 and it worked like a charm! Thank you for the problem solving up till now!

This discussion is preserved as it was. New answers, comments, and votes are closed.