#How do I make a kill detection script using profile service

1 messages · Page 1 of 1 (latest)

pine smelt
#

Title

solid folio
#

Use KillDetectionUsingProfileServiceService

timber stump
wild dawn
#

isnt profile service a datastore handler?

lavish panther
#

local ProfileService = require(path.to.ProfileService)

local Players = game:GetService("Players")
local Profiles = {}
local DataTemplate = {
Kills = 0
}

local ProfileStore = ProfileService.GetProfileStore("PlayerData", DataTemplate)

Players.PlayerAdded:Connect(function(player)
local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)

if profile then
    profile:Reconcile()
    profile:ListenToRelease(function()
        Profiles[player] = nil
        player:Kick("Your data has been released.")
    end)

    if player:IsDescendantOf(Players) then
        Profiles[player] = profile
    else
        profile:Release()
    end
else
    player:Kick("Failed to load data.")
end

end)

Players.PlayerRemoving:Connect(function(player)
if Profiles[player] then
Profiles[player]:Release()
end
end)

#

local function onEnemyKilled(killerPlayer)
local profile = Profiles[killerPlayer]
if profile then
profile.Data.Kills += 1
print(killerPlayer.Name .. " now has " .. profile.Data.Kills .. " kills!")
end
end

#

humanoid.Died:Connect(function()
local tag = humanoid:FindFirstChild("creator") -- Roblox's convention for damage tags
if tag and tag.Value and tag.Value:IsA("Player") then
onEnemyKilled(tag.Value)
end
end)

lavish panther
#

Full disclosure that is AI

#

But it will work

lavish panther