What do you want to achieve?
I want to make leaderboard which counting player kills.
Here is my script:
local Players = game:GetService("Players")
local enemy = workspace.Dummy
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "KillStreak"
kills.Value = 0
kills.Parent = leaderstats
enemy.Humanoid.Died:Connect(function()
kills.Value += 1
end)
end)
This script is counting when I kill one npc when I need script working on several npcs. So i have multiple npcs and kill value add 1 for every kill npc.
Well, I would put all enemy instances into a folder, and use a loop. For example:
local enemy_folder = -- // Path to your folder, presumably in the workspace
for _,enemy in pairs (enemy_folder:GetChildren()) do
enemy.Humanoid.Died:Connect(function()
kills.Value += 1
end)
end
I don’t know if it would work like this if you were to fill out the path to the enemy folder and insert the example script into the PlayerAdded function. If not, you have a good base script you could work with.