silver4804
(silver4804)
November 3, 2022, 1:23am
1
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)
DasKairo
(Cairo)
November 3, 2022, 1:37am
2
silver4804:
Set Attribute isn’t working, perhaps it doesn’t work on players?
player:SetAttribute("Strength", 0)
player:SetAttribute("Speed", 0)
player:SetAttribute("Stamina", 0)
player:SetAttribute("LungCapacity", 0)
player:SetAttribute("MaxRegeneration", 0)
You are not specifying what the Attributes are.
silver4804
(silver4804)
November 3, 2022, 1:41am
3
what do you mean? like im not specifying whether its an int value or string?
DasKairo
(Cairo)
November 3, 2022, 2:05am
4
exactly, you are trying to set up an Attribute without Specifying what it is.
silver4804
(silver4804)
November 3, 2022, 2:06am
5
im specifying it by putting a 0
7z99
(cody)
November 3, 2022, 2:21am
6
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.
MakerDoe
(Dez)
November 3, 2022, 3:02am
7
silver4804:
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)
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.
MakerDoe
(Dez)
November 3, 2022, 3:10am
8
silver4804:
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])
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.