i tried make a database system to store the players leaderstats however on line 51 I’m getting an error message
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)