Leaderstats adding problem

hello, i have a script in my game:

local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function()
	local tag = hum:FindFirstChild("creator")
	if tag then
		local player = tag.Value
		local kills = player.leaderstats.Kills
		local streak = player.leaderstats.Streak
		local maxstreak = player.MaxStreak
		kills.Value += 1
		streak.Value += 1
		if maxstreak.Value > streak.Value then
			maxstreak.Value += 1
		end
	end	
end)

basically, when a player gets a kill, there are 3 values that are changed
-Kills (the total amount of kills they have)
-Streak (the current kill streak they are on, resets after they die)
-Max Streak (the highest streak they have ever reached before dying)

The problem is, the Max Streak is going up by +1, even if i have never actually reached that streak, it just goes up with every kill. I only want it to display the highest kill streak the player has reached

if streak.Value > maxstreak.Value then
	maxstreak.Value += 1
end

The reason your code doesnt work is because if maxstreak.Value > streak.Value then is always true. If your current kill streak was 2 and the max kill streak was 3, this is what your asking the code to do: 3 > 2 which is true.
So try the code above and see if it works. Good luck on making your game!

1 Like

Hello, thank you for your response. I tried your code but for some reason, it is still increasing ‘MaxStreak’ despite it not being the highest amount as before

For example, I die with 6 streak and my Streak is set to 0, I get a kill and my streak goes to 1, but my maxstreak goes to 7 now

Maybe your code is adding on to the previous score you had before you died? Maybe try to check that out.

1 Like

The ‘streak’ leaderstat is set to 0 every time the player dies, but ‘Kills’ and ‘MaxStreak’ will save all time

The code is currently checking if the maxstreak.Value is greater than the streak.Value , which will always be true if the maxstreak.Value is initially set to 0.

you need to change the conditional statement to check if the streak.Value is greater than the maxstreak.Value

local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function()
	local tag = hum:FindFirstChild("creator")
	if tag then
		local player = tag.Value
		local kills = player.leaderstats.Kills
		local streak = player.leaderstats.Streak
		local maxstreak = player.MaxStreak
		kills.Value += 1
		streak.Value += 1
		if streak.Value > maxstreak.Value then
			maxstreak.Value = streak.Value
		end
	end	
end)
1 Like

Hello, thank you for your reply. Unfortunately, this did not solve my problem, as the max streak will keep going +1 per kill, even if the streak is 0

local hum = script.Parent:WaitForChild("Humanoid")

hum.Died:Connect(function()
	local tag = hum:FindFirstChild("creator")
	if tag then
		local player = tag.Value
		local kills = player.leaderstats.Kills
		local streak = player.leaderstats.Streak
		local maxstreak = player.MaxStreak
		kills.Value += 1
		streak.Value += 1
		if maxstreak.Value > streak.Value then
			maxstreak.Value += 1
		end
        print(maxstreak.Value, streak.Value)
	end	
end)

can you execute this and say the output ?

1 Like

its not printing anything in the output for some reason

hmm… is there any error in the code ?

1 Like