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

Why isn't my newer DataStore not load/saving any data?

I recently changed up my DataStore System and was wondering why is wasn't working (I have tried this out of studio)any ideas? any help would be appreciated

local DataStoreService = game:GetService("DataStoreService")
local DATA = DataStoreService:GetDataStore("DATA")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cash = Instance.new("NumberValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats
	
	local data
	local success, errormessage = pcall (function()
		data = DATA:GetAsync(player.UserId.."-cash")
	end)
	if success then
		cash.Value = data
	else
		print("An error occurred while loading player data")
		warn(error)
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall (function()
		DATA:SetAsync(player.UserID.."-cash",player.leaderstats.Cash.Value)
	end)
	
	if success then
		print("Player Data successfully saved!")
	else
		print("An error occurred while saving player data")
		warn(errormessage)
	end
	
end)

The Script is named Script

Edit:I am getting a console error of couldn't identity player.UserId

1 comment

0

You forgot an = in line 28. Also in line 21, I think you were suppose to write warn(errormessage) instead of warn(error).

1 answer

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