Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this happening in DataStore2?

Asked by 3 years ago

So I'm making a game, sort of like Corridors Of Hell, but the Datastore2 implications are not working. Here is the code that increments the value:

local p = game.Players:GetChildren()
wait(0)
for i = 1, #p do
    if p[i].AFK.Value == false and p[i].Character ~= nil then
        if table.find(noncowards, p[i].Name) ~= nil and p[i].Character.PrimaryPart.Position.Z > 549.4 and p[i].Character.Humanoid.Health > 0 then
            table.remove(noncowards, table.find(noncowards, p[i].Name))
            p[i].Character.Humanoid.Health = 0
            local pointsDataStore = DataStore2("Wins", p[i])
            pointsDataStore:Increment(1, 0)
            pointsDataStore = DataStore2("Points", p[i])
            pointsDataStore:Increment(250, 150)
            game.ReplicatedStorage.StormSpeed.Value = game.ReplicatedStorage.StormSpeed.Value * 2
            dmg = dmg * 2
            game.ReplicatedStorage.Wins.Value = game.ReplicatedStorage.Wins.Value + 1
        elseif p[i].Character.Humanoid.Health < 0.000000001 and table.find(noncowards, p[i].Name) ~= nil then
            local zz = p[i].Character.PrimaryPart.Position.Z
            local pointsDataStore = DataStore2("Points", p[i])
            pointsDataStore:Increment(((math.floor((zz + 952.605) / 150.2) * 25) * (game.ReplicatedStorage.Boosts.Extra.Value + 1)))
            table.remove(noncowards, table.find(noncowards, p[i].Name))
            print("Removed By Death")
        end
    end

BTW, I do close end later on in the code for the for loop. This is the error I got:

Model.MainModule:249: attempt to perform arithmetic (add) on nil and number

What is it referring to and why is this popping up?

Answer this question