sorry for a bad english im trying my best
so, i have this leaderstats that detects players kills, death and kill streaks.
the only problem is that when i change skins, for reason everytime i killed someone or Get killed by someone, it for some reason it duplicates it.
heres the video and pay attention to the Deaths
External Medianow I’ve used this particular character shop in the game, because im bad at scripting at the moment
and this is the leaderstats that ive used
local dss = game:GetService("DataStoreService")
local levelDS = dss:GetDataStore("Levels")
stands = {}
CTF_mode = false
function incrementExp(player, increment)
for i = player.Stats.Experience.Value, player.Stats.Experience.Value + increment do
player.Stats.Experience.Value = i
wait()
end
end
function saveData(player)
pcall(function()
local level = player.Stats.Level.Value
local exp = player.Stats.Experience.Value
levelDS:SetAsync(player.UserId .. "Level", {level, exp})
end)
end
function onHumanoidDied(humanoid, player)
local stats = player:findFirstChild("leaderstats")
if stats ~= nil then
local deaths = stats:findFirstChild("Deaths")
local spree = stats:findFirstChild("Kill Streak")
game:GetService("ReplicatedStorage").DisplayDeath:FireClient(player)
deaths.Value += 1
spree.Value = 0
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
handleKillCount(humanoid, player)
end
end
function onPlayerRespawn(property, player)
if property == "Character" and player.Character ~= nil then
local humanoid = player.Character.Humanoid
local p = player
local h = humanoid
humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then
return killer
end
end
return nil
end
function handleKillCount(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if killer ~= nil then
local stats = killer:findFirstChild("leaderstats")
local Cash = killer:findFirstChild("PlayerData"):findFirstChild("Cash")
local levelValue = killer:findFirstChild("Stats"):findFirstChild("Level")
local Experience = killer:findFirstChild("Stats"):findFirstChild("Experience")
if stats ~= nil then
local kills = stats:findFirstChild("Kills")
local spree = stats:findFirstChild("Kill Streak")
local MatchFolder = killer:findFirstChild("MatchFolder")
local MatchKIlls = MatchFolder:findFirstChild("MatchKIlls")
if killer ~= player then
local neededExp = math.floor(levelValue.Value ^ 1.5 + 0.5) * 500
if Experience.Value >= neededExp then
levelValue.Value += 1
end
incrementExp(killer, 100)
MatchKIlls.Value = MatchKIlls.Value + 1
kills.Value += 1
spree.Value += 1
game:GetService("ReplicatedStorage").DisplayKill:FireClient(killer)
Cash.Value = Cash.Value + 10
--streak
if spree.Value == 0 then
game:GetService("ReplicatedStorage").StreakImage.Streak1:FireClient(killer)
end
if spree.Value == 1 then
game:GetService("ReplicatedStorage").StreakImage.Streak2:FireClient(killer)
end
if spree.Value == 2 then
game:GetService("ReplicatedStorage").StreakImage.Streak3:FireClient(killer)
end
if spree.Value == 3 then
game:GetService("ReplicatedStorage").StreakImage.Streak4:FireClient(killer)
end
if spree.Value == 4 then
game:GetService("ReplicatedStorage").StreakImage.Streak5:FireClient(killer)
end
if spree.Value == 5 then
game:GetService("ReplicatedStorage").StreakImage.Streakinvisible:FireClient(killer)
end
if spree.Value == 9 then
game:GetService("ReplicatedStorage").StreakImage.Streak10:FireClient(killer)
Cash.Value = Cash.Value + 50
end
if spree.Value == 10 then
game:GetService("ReplicatedStorage").StreakImage.Streakinvisible:FireClient(killer)
Cash.Value = Cash.Value + 50
incrementExp(killer, 250)
end
if spree.Value == 19 then
game:GetService("ReplicatedStorage").StreakImage.Streak20:FireClient(killer)
end
if spree.Value == 20 then
game:GetService("ReplicatedStorage").StreakImage.Streakinvisible:FireClient(killer)
end
if spree.Value == 49 then
game:GetService("ReplicatedStorage").StreakImage.Streak50:FireClient(killer)
end
if spree.Value == 50 then
game:GetService("ReplicatedStorage").StreakImage.Streakinvisible:FireClient(killer)
Cash.Value = Cash.Value + 100
end
if spree.Value >= 50 then
game:GetService("ReplicatedStorage").StreakImage.Godlike:FireAllClients(killer)
game:GetService("ReplicatedStorage").StreakImage.Streakinvisible:FireClient(killer)
incrementExp(killer, 500)
end
else
kills.Value += 1
end
end
end
end
-----------------------------------------------
function findAllFlagStands(root)
local c = root:children()
for i=1,#c do
if (c[i].className == "Model" or c[i].className == "Part") then
findAllFlagStands(c[i])
end
if (c[i].className == "FlagStand") then
table.insert(stands, c[i])
end
end
end
--[[
function hookUpListeners()
for i=1,#stands do
stands[i].FlagCaptured:connect(onCaptureScored)
end
end
]]
function onPlayerEntered(newPlayer)
if CTF_mode == true then
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local captures = Instance.new("IntValue")
captures.Name = "Captures"
captures.Value = 0
captures.Parent = stats
while true do
if newPlayer.Character ~= nil then
break
end
wait(5)
end
stats.Parent = newPlayer
else
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Value = 0
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = 0
local spree = Instance.new("IntValue")
spree.Name = "Kill Streak"
spree.Value = 0
kills.Parent = stats
deaths.Parent = stats
spree.Parent = stats
while true do
if newPlayer.Character ~= nil then
break
end
wait(5)
end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
stats.Parent = newPlayer
end
end
--[[
function onCaptureScored(player)
local ls = player:findFirstChild("leaderstats")
if ls == nil then return end
local caps = ls:findFirstChild("Captures")
if caps == nil then return end
caps.Value = caps.Value + 1
end
]]
findAllFlagStands(game.Workspace)
-- hookUpListeners()
if (#stands > 0) then
CTF_mode = true
end
game.Players.ChildAdded:connect(onPlayerEntered)
game.Players.PlayerAdded:Connect(function(player)
local statsFolder = Instance.new("Folder", player)
statsFolder.Name = "Stats"
local levelVal = Instance.new("IntValue", statsFolder)
levelVal.Name = "Level"
levelVal.Value = 1
local expVal = Instance.new("IntValue", statsFolder)
expVal.Name = "Experience"
pcall(function()
local data = levelDS:GetAsync(player.UserId .. "Level")
if data then
levelVal.Value = data[1]
expVal.Value = data[2]
end
end)
local function RewardsSystem()
if levelVal.Value >= 5 then
if player:FindFirstChild("OwnedCharacters"):FindFirstChild("Tom") then
--None
else
game:FindFirstChild("ReplicatedStorage"):FindFirstChild("CharactersFolder"):FindFirstChild("Tom"):Clone().Parent = player.OwnedCharacters
end
end
if levelVal.Value >= 10 then
if player:FindFirstChild("OwnedCharacters"):FindFirstChild("Alen") then
--None
else
game:FindFirstChild("ReplicatedStorage"):FindFirstChild("CharactersFolder"):FindFirstChild("Alen"):Clone().Parent = player.OwnedCharacters
end
end
if levelVal.Value >= 15 then
if player:FindFirstChild("OwnedCharacters"):FindFirstChild("Ghost Face") then
--None
else
game:FindFirstChild("ReplicatedStorage"):FindFirstChild("CharactersFolder"):FindFirstChild("Ghost Face"):Clone().Parent = player.OwnedCharacters
end
end
if levelVal.Value >= 20 then
if player:FindFirstChild("OwnedCharacters"):FindFirstChild("Nerd Emoji") then
--None
else
game:FindFirstChild("ReplicatedStorage"):FindFirstChild("CharactersFolder"):FindFirstChild("Nerd Emoji"):Clone().Parent = player.OwnedCharacters
end
end
if levelVal.Value >= 50 then
if player:FindFirstChild("OwnedCharacters"):FindFirstChild("Frostbite") then
--None
else
game:FindFirstChild("ReplicatedStorage"):FindFirstChild("CharactersFolder"):FindFirstChild("Frostbite"):Clone().Parent = player.OwnedCharacters
end
end
end
RewardsSystem()
levelVal:GetPropertyChangedSignal("Value"):Connect(function()
RewardsSystem()
end)
end)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
its really just a bunch of scripts i combined together to a some what functioning leaderstats