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

The DataStoreService does not save the player data. What is wrong with this script?

The error message for the First Function prints "nil"

local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("Points")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue", leaderstats)
	points.Name = "Points"
	points.Value = 4
	
	local PlayerID = player.UserId
	
	local data
	local success, errormessage pcall(function()
		data = PlayerDataStore:GetAsync(PlayerID)
	end)
	
	
	if success then
		local points = player.leaderstats.Points
		points.Value = data
	else
			warn(errormessage)
	
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	local data = player.leaderstats.Points.Value
	local PlayerID = player.UserId
	local success, errormessage = pcall(function()
			PlayerDataStore:SetAsync(PlayerID, data)
			
		end)
		if success then
			print("Player data has been saved")
	else
				warn(errormessage)
		end
end)

1 answer

You forgot to have an = sign before pcall on line 15. Also, you don't have to define points again on line 21 because it will still know what points is.

1 comment

0

thanks it works now

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