Issue with datastore

i tried make a database system to store the players leaderstats however on line 51 I’m getting an error message
image
I know that its an issue with setting the data values to data, but I’m trying to make it set the value to the player data rather then the actual term ‘data’

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

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

	local Faction = Instance.new('StringValue')
	Faction.Name = 'Faction'
	Faction.Value = 'None'
	Faction.Parent = leaderstats

	local Rank = Instance.new('StringValue')
	Rank.Name = 'Rank'
	Rank.Value = 'None'
	Rank.Parent = leaderstats

	local BusoHaki = Instance.new('IntValue')
	BusoHaki.Name = 'BusoHaki'
	BusoHaki.Value = 0
	BusoHaki.Parent = leaderstats

	local KenHaki = Instance.new('IntValue')
	KenHaki.Name = 'KenHaki'
	KenHaki.Value = 0
	KenHaki.Parent = leaderstats

	local DevilFruit = Instance.new('StringValue')
	DevilFruit.Name = 'DevilFruit'
	DevilFruit.Value = 'None'
	DevilFruit.Parent = leaderstats

	local Bounty = Instance.new('IntValue')
	Bounty.Name = 'Bounty'
	Bounty.Value = 0
	Bounty.Parent = leaderstats

	local Reputation = Instance.new('IntValue')
	Reputation.Name = 'Reputation'
	Reputation.Value = 0
	Reputation.Parent = leaderstats


	local data
	local success, errormessage = pcall(function()
		data = DataStore:GetAsync(player.UserId)
	end)

	if success then
		Faction.Value = data
		Rank.Value = data
		BusoHaki.Value = data
		KenHaki.Value = data
		DevilFruit.Value = data
		Bounty.Value = data
		Reputation.Value = data
		
	else
		print("There was an error whilst getting your data")
		warn(errormessage)
	end
	

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DataStore:SetAsync(player.UserId)
	end)

	if success then
		print("Player Data successfully saved!")
	else
		warn("There was an error when saving data") 
		warn(errormessage)
	end
end)

game:BindToClose(function()
	task.wait(5)
end)

end)

I think you need to look over the documentation for working with Data stores | Documentation - Roblox Creator Hub some more.

You would need to pass in an, usually a table of data to save along with the key when calling setasync if you want to actually save anything.

And then when trying to pull data out and assigning it to those keaderstat values you would do something like
reputation.Value = data.reputation

But again, I would start by looking over their examples and documentation first to understand how to use it better.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.