- Is it possible to create a kill count system using different tools with different damage and hitbox systems?
My Leaderstats:
local DataStoreService = game:GetService(“DataStoreService”)
local killsDataStore = DataStoreService:GetDataStore(“PlayerKills”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = leaderstats
local success, savedKills = pcall(function()
return killsDataStore:GetAsync(player.UserId)
end)
if success then
kills.Value = savedKills or 0
else
warn("Não foi possível carregar os dados para " .. player.Name)
end
player.AncestryChanged:Connect(function()
if not player:IsDescendantOf(game) then
pcall(function()
killsDataStore:SetAsync(player.UserId, kills.Value)
end)
end
end)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.Died:Connect(function()
local killer = humanoid:FindFirstChild(“creator”) – Localiza o killer (criador do dano)
if killer and killer.Value and killer.Value:IsA(“Player”) then
local killerPlayer = killer.Value
if killerPlayer and killerPlayer:FindFirstChild(“leaderstats”) then
local kills = killerPlayer.leaderstats:FindFirstChild(“Kills”)
if kills then
kills.Value += 1
end
end
end
end)
end
end)
end)