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"
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)