Basically I've just started creating a game and I've already got a problem.. Basically when you join the game you'll see a gui. In that gui you can choose an ability, like Aqua, Or Fire or Melee. But when ever i run this script:
local datastoresev = game:GetService("DataStoreService")
local AbilityStore1 = datastoresev:GetDataStore("AbilityStore1")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Ability = Instance.new("StringValue")
Ability.Name = "Ability"
Ability.Parent = leaderstats
playeruserid = "Player_"..player.UserId
AbilityStore1:GetAsync(playeruserid)
-- Load--
local success, errormessage = pcall(function()
data = AbilityStore1:GetAsync(playeruserid)
end)
if success then
Ability.Value = data[1]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = {player.leaderstats.Ability.Value}
local success, errormessage = pcall(function()
AbilityStore1:SetAsync(playeruserid, data)
end)
if success then
print("Data Successfully Saved")
else
print("There was an error when saving player's ability")
warn(errormessage)
end
end)
Again?! Jeez I'm really not good with datastores. Now it says that on line 22 I'm trying to index nil with a number? It's the same line over and over again I don't know what I did wrong.. So sorry for making you return to this issue....

4 comments
I fixed the second issue, check my answer again
Sorry, that worked but now... it says im trying to index nil with a number, when will this trauma end?
It means you're indexing nil with a number... So the thing you're indexing is a number.
o what do i do?