In my game, you get a streak and it gives you a benefit. However, some people as soon as they die use the rejoin command and quickly save this streak. I’d somewhat patched it, but it still works if you do it fast enough. Is there any way to patch this? I use a Died event to detect when to remove spree.
May we see your Died
event code to see what could be done to help improve it
players.PlayerAdded:Connect(function(plr)
createStats(plr)
local kills = plr.leaderstats.Kills
local spree = plr.leaderstats.Spree
local topSpree = plr.leaderstats.TopSpree
plr.CharacterAdded:Connect(function(c)
local humanoid = c:WaitForChild("Humanoid", 7)
if humanoid then
humanoid.Died:Connect(function()
local leaderstats = plr:WaitForChild("leaderstats", 7)
if leaderstats then
if leaderstats.Spree.Value > leaderstats.TopSpree.Value then
leaderstats.TopSpree.Value = leaderstats.Spree.Value
end
leaderstats.Spree.Value = 0
local killer
for i, Child in pairs(c:GetDescendants()) do
if Child:IsA("ObjectValue") and Child.Value ~= nil and Child.Value:IsA("Player") then
killer = Child.Value
end
end
if killer ~= nil then
killer.leaderstats.Kills.Value += 1
killer.leaderstats.Spree.Value += 1
end
end
end)
end
end)
end)
I think what could be done is to just reference the variables you alreayd have for the player leaderstats rather than make them again, could help reduce some time in which it sets the values. I’m not sure if this would help out but maybe use this?
players.PlayerAdded:Connect(function(plr)
createStats(plr)
local kills = plr.leaderstats.Kills
local spree = plr.leaderstats.Spree
local topSpree = plr.leaderstats.TopSpree
plr.CharacterAdded:Connect(function(c)
local humanoid = c:WaitForChild("Humanoid", 7)
if humanoid then
--This is in a player added so you don't need a WaitForChild for the leaderstats
humanoid.Died:Connect(function()
if spree.Value > TopSpree.Value then
topSpree.Value = spree.Value
end
spree.Value = 0
local killer
for i, Child in pairs(c:GetDescendants()) do
if Child:IsA("ObjectValue") and Child.Value ~= nil and Child.Value:IsA("Player") then
killer = Child.Value
break
end
end
if killer ~= nil then
killer.leaderstats.Kills.Value += 1
killer.leaderstats.Spree.Value += 1
end
end)
end
end)
end)
Thank you for the help; I will mark this as a solution as it is the best answer I have gotten so far.
1 Like