I just need a script that will reset their "streak" leaderstat if they die. I do not have any sample script cause im t r a s h at scripting, so Any Help is very much Appreciated!
How do i make it so a "streak" leaderstat resets on player death?
4 answers
A general tip I like to give people that are new to programming/coding is to do a web search about their issue. Something like "how to check if a player dies roblox" would return exactly what you are looking for.
As for how to check if a player dies, you would use a Humanoid event, Humanoid.Died.
local Humanoid = Player.Character.Humanoid
Humanoid.Died:Connect(function()
-- Code here
end)
For the leaderstats reset, you should make an attempt to figure it out. If you are having trouble though, feel free to contact me on Discord (phxntxsmic#2021) and I will be happy to help you out further.
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) local humanoid = char:WaitForChild("Humanoid") local deaths = humanoid:BreakJoints() local folder = Instance.new("Folder", deaths)
folder.Name = "Streak"
local stringvalue = Instance.new("NumberValue", folder)
stringvalue.Value = 10
if deaths then
stringvalue.Value = 0
--Add DataStore If u wanna do it permantly
end
end)
end) notify me if it doesnt work also dont copy this line**************
1 comment
I am confused by your code. Model:BreakJoints()'s return type is void; it doesn't return a useable value. You are also not checking for a player's death.
Erm.. I understand that you are having trouble, but please try to provide any sample or attempt. Such as your leaderstats.
Well the answer is simple, so I would wanna give you a proper explanation as well..
First we are gonna define our player service, and then listen for its PlayerAdded event. We will then proceed to create our leaderstats folder, and put it into the player object.
our leaderstats would basically be:
- A folder named leaderstats
- an IntValue (integer value) within the leaderstats folder.
we will then listen to the players CharacterAdded event, which keep in mind gives us the character as the first parameter, and that the humanoid will indeed be there once fired.
Finally we will listen for the humanoids Died event, and then set the streak value to 0
This would all look like this:
local playersService = game:GetService("Players")
playersService.PlayerAdded:Connect(function(player)
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
leaderstatsFolder.Parent = player
local streak = Instance.new("IntValue")
streak.Name = "Streak"
streak.Value = 0
streak.Parent = leaderstatsFolder
player.CharacterAdded:Connect(function(character)
local humanoid = character.Humanoid
humanoid.Died:Connect(function()
player.leaderstats.Streak.Value = 0
end)
end)
end)
Sorry, but where would this go?
1 comment
I also already have all of the stats, so can you just make it so when i die i lose the streak?
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) local humanoid = char:WaitForChild("Humanoid") local deaths = humanoid:BreakJoints() local folder = Instance.new("Folder", deaths) folder.Name = "Streak" local stringvalue = Instance.new("NumberValue", folder) stringvalue.Value = 10 if deaths then stringvalue.Value = 0 --Add DataStore I