When i tried putting datastore in my game, it just gives 3 errors ('kills is not a valid member of Folder "Players.Player2.leaderstats"', ' Script 'ServerScriptService.Leaderboard', Line 45 - function saveData', and 'Script 'ServerScriptService.Leaderboard', Line 57'). Idk how to fix it, since I havent seen any typos. Thoughts?
BTW here's the script:
local DataStore = game:GetService("DataStoreService")
local PlrDataStore = DataStore:GetDataStore("PlayerData")
local function onPlayerJoin(player)
local leaderstats = Instance.new('Folder') --creates a new folder
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local kills = Instance.new('IntValue') --creates int value
kills.Name = "Kills" --name of the kills
kills.Value = 0 --its value
kills.Parent = leaderstats --parent of kills (same goes for deaths)
local deaths = Instance.new('IntValue')
deaths.Name = "Deaths"
deaths.Value = 0
deaths.Parent = leaderstats
local killer = Instance.new('StringValue') --makes a killer tag for the player
killer.Name = 'Killer'
killer.Parent = player
local PlayerData
local Success, ErrorMsg = pcall(function()
local PlayerId = player.UserId
PlayerData = PlrDataStore:GetAsync(PlayerId)
end)
if Success then
print("success data load")
if PlayerData then
kills.Value = PlayerData[1]
deaths.Value = PlayerData[2]
end
else
warn(ErrorMsg)
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin) --when a player joins the game