SetAttribute not applying to Player

Set Attribute isn’t working, perhaps it doesn’t work on players?

local Datastore = game:GetService("DataStoreService")
local NADS = Datastore:GetDataStore("NADS")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Bounty = Instance.new("IntValue")
	Bounty.Name = "Bounty"
	Bounty.Parent = leaderstats
	
	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Parent = player
	
	local Exploiting = Instance.new("BoolValue")
	Exploiting.Name = "Exploiting"
	Exploiting.Parent = player
	
	-- stats

	player:SetAttribute("Strength", 0)
	player:SetAttribute("Speed", 0)
	player:SetAttribute("Stamina", 0)
	player:SetAttribute("LungCapacity", 0)
	player:SetAttribute("MaxRegeneration", 0)

	local data = NADS:GetAsync(player.UserId)
	
	if data ~= nil then
		Bounty.Value = data[1]
		Money.Value = data[2]
		player:SetAttribute("Strength", data[3])
		player:SetAttribute("Speed", data[4])
		player:SetAttribute("Stamina", data[5])
		player:SetAttribute("LungCapacity", data[6])
		player:SetAttribute("MaxRegeneration", data[7])
	else
		player:SetAttribute("Strength", 50)
		player:SetAttribute("Speed", 16)
		player:SetAttribute("Stamina", 100)
		player:SetAttribute("LungCapacity", 20)
		player:SetAttribute("MaxRegeneration", 50)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	local save = {
		player.leaderstats.Bounty.Value,
		player.Money.Value,
		strength = player:GetAttribute("Strength"),
		speed = player:GetAttribute("Speed"),
		stamina = player:GetAttribute("Stamina"),
		LC = player:GetAttribute("Lung Capacity"),
		MR = player:GetAttribute("Max Regeneration"),
	}
	print(save)
	NADS:SetAsync(player.UserId, save)
end)

You are not specifying what the Attributes are.

what do you mean? like im not specifying whether its an int value or string?

exactly, you are trying to set up an Attribute without Specifying what it is.

im specifying it by putting a 0

When saving you’re using a mix of string and numerical indexes, but when you go to load you’re using numerical indexes. Since data stores don’t work with mixed key tables, you need to settle on either numerical or string indexes.

This isn’t possible because tables are encoded into JSON when using the datastore service. You need to separate them because they are of different data types; the indexes 0 and 1 are arrays, while the rest are objects.

local save = {
	attributes = { -- this key is now an array
		player.leaderstats.Bounty.Value,
		player.Money.Value,
	},

	speed = player:GetAttribute("Speed"),
	stamina = player:GetAttribute("Stamina"),
	LC = player:GetAttribute("Lung Capacity"),
	MR = player:GetAttribute("Max Regeneration"),
}

Also, I’m pretty sure that this was the issue since I have used set attributes before on players.

Also, I just noticed that 3 through 7 will just give you a null value since they don’t exist. You have specified that they contain a key; you simply have to call or index the key: data.strength.