Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make it so a "streak" leaderstat resets on player death?

Asked by 3 years ago
Edited 3 years ago

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!

0
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 LovelyRoyston 0 — 3y

4 answers

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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.

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
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. appxritixn 2235 — 3y
Log in to vote
0
Answered by 3 years ago

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: 1) A folder named leaderstats 2) 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)
Log in to vote
0
Answered by 3 years ago

Sorry, but where would this go?

0
I also already have all of the stats, so can you just make it so when i die i lose the streak? Julien999111 0 — 3y

Answer this question