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

IncrementAsync not an int value?

Asked by 3 years ago
local DataStoreService = game:GetService("DataStoreService")

local deaths = DataStoreService:GetDataStore("PlayerDeaths")


local function onPlayerJoin(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player


    local deaths = Instance.new("IntValue")
    deaths.Name = "Accidents"
    deaths.Parent = leaderstats


    player.CharacterAdded:Connect(function(char)
        -- detect humanoid died.
        char.Humanoid.Died:Connect(function()
            print("e")
            local success, newDeath = pcall(function()
                print("ee")
                return deaths:IncrementAsync(player.UserId, 1)

            end)
            print(newDeath)
            if success then
                deaths.Value = newDeath-- add 1 value to values
                print(newDeath)
            end
        end)
    end)
end



game.Players.PlayerAdded:Connect(onPlayerJoin)

e and ee print the first newDeath results in "IncrementAsync is not a valid member of IntValue"

1 answer

Log in to vote
1
Answered by
DevingDev 346 Moderation Voter
3 years ago

You have 2 variables with the same name; deaths and deaths. One of them is of type IntValue and the other one is a Datastore.

Renaming of the deaths variable should do the trick. I recommend that you rename the first deaths variable to something like

local deathsDatastore = DataStoreService:GetDataStore("PlayerDeaths")

and

local deaths = Instance.new("IntValue")
deaths.Name = "Accidents"
deaths.Parent = leaderstats

You'll now need to change line 23 to

return deathsDatastore:IncrementAsync(player.UserId, 1)
0
thanks i done goofed jamespringles 105 — 3y
Ad

Answer this question