So i am working on my game and i got stuck on this problem. So basically i have a simple leaderboard script and i want to detect and add kills to the player that killed a "NCP".
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MoneyStats") -- Change this with a different name.
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Money= Instance.new("IntValue", Leaderstats)
Money.Name = "Money" -- Change "Money" with your currency.
Money.Value = 0
local Kills= Instance.new("IntValue", Leaderstats)
Kills.Name = "Kills" -- Change "Kills" with your currency.
Kills.Value = 0
local Data = DataStore:GetAsync(Player.UserId)
if Data then
Money.Value = Data.Money -- Change "Money" with your currency.
Kills.Value = Data.Kills -- Change "Kills" with your currency.
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, {
["Money"] = Player.leaderstats.Money.Value; -- Change "Money" with your currency.
["Kills"] = Player.leaderstats.Kills.Value; -- Change "Kills" with your currency.
})
end)
This is the Leaderboard scrip just in case.
Note: I am using the official weapon kit from roblox for the detecting part
