How do you make a Jump counter leaderboard?

I am trying to make a jump counter for a simple game. The script has some bugs.

The Script is supposed to give one point for every jump you make, but when holding the spacebar it says the player did 2 jumps.

Here’s the script so far:

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player 

    local jumpCount = Instance.new("IntValue")
    jumpCount.Name = "Jumps"
    jumpCount.Parent = leaderstats

    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        humanoid.StateChanged:Connect(function(oldState, newState)
            if newState == Enum.HumanoidStateType.Jumping then
                jumpCount.Value = jumpCount.Value + 1
            end
        end)
    end)
end)
2 Likes

You could try attaching a :GetPropertyChangedSignal to Humanoid.Jump and then increment a number value that you store for your leaderboard. Or you could do something like:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local jumpCount = -- [[path to some number value]]

local function countJump(Character)

    local humanoid = Character:WaitForChild("Humanoid")

    humanoid.StateChange:Connect(function(oldState, newState)
        if newState == Enum.HumanoidStateType.Jumping then
            jumpCount.Value = jumpCount.Value + 1
        end
    end)
end

Player.CharacterAdded:Connect(countJump)

2 Likes

A few things.

Firstly, I believe that the code enforces bad practice when all this could be run on the server, which your code seemed to be very well compatible for. Although for some reason, you put it in the client. I wouldn’t rely on the client and there are a bunch of articles supporting this.

Secondly (this is a small thing). You made a typo, it is humanoid.StateChange(d) not stateChange

Thirdly, when you set this up in a serverside code, we do not need the use of :GetPropertyChangedSignal, leaving us with less callback functions :slight_smile:

But, if we want to use client, may I suggest changing the code where you do

local Character = player.Character or player.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")

humanoid.StateChange:Connect(function(oldState, newState)
   if newState == Enum.HumanoidStateType.Jumping then
      jumpCount.Value = jumpCount.Value + 1
   end
end)

^I believe this to be cleaner

2 Likes
game.Players.PlayerAdded:Connect(function(player) -- whenever a player joins
    local leaderstats = Instance.new("Folder") -- let's create the leaderstats here!
    leaderstats.Name = "leaderstats"-- it must be this string 
    leaderstats.Parent = player 

    local jumpCount = Instance.new("IntValue") -- A value that stores data in the form of numbers
    jumpCount.Name = "Jumps" -- What you want the value's name to be displayed on the leaderboard

    player.CharacterAdded:Connect(function(character) -- Using the nifty code from GGGGG14
        local humanoid = character:WaitForChild("Humanoid")
        humanoid.StateChange:Connect(function(oldState, newState) -- Whenever the humanoid shifts state
            if newState == Enum.HumanoidStateType.Jumping then --If the state we change to is "jump"
                jumpCount.Value = jumpCount.Value + 1 -- We add onto our leaderstat :)
            end
        end)
    end)
end)
1 Like

Unless OP needs the code to be on the server, I think keeping it on the client is fine. An exploiter can also set their humanoid’s state to “Jumping” whenever they want, and it will replicate to the server, so having it on the server is just an extra step when both are easily exploitable.


Of course, putting it on the server or on the client is just preference from what information OP gave us.

1 Like

Right, I didn’t think of that perspective! How about using Humanoid.FloorMaterial, is that changeable?

In the API Reference, it says FloorMaterial is nonreplicated, and its readonly, so it should be perfectly safe to use. Of course, I’m not completely sure.

2 Likes

Would i put this in starter player scripts?

ServerScriptService would be the appropriate service, unless you are putting it on the client. If you are putting it on the client, yes, StarterPlayerScripts.

robloxapp-20200322-1101085.wmv (1.1 MB)
Is there something i have to name the script? or use a specific one?

1 Like

Not really you can name it however you wan’t and then if you wan’t to use it for another scripts just define it , example:

local Script = game.ServerScriptServer.ScriptName

Where did you place the script?

I put it in ServerScriptServer

In this case, you are using a LocalScript, which does not function on the server, thus rendering it as null when placing it in ServerScriptService. Go ahead and place the LocalScript into StarterPlayerScripts.

You can’t place a LocalScript in ServerScriptService as it will just get placed back where it was previously.
@NoxiousVoid it should be just a Server Script (normal Script) in ServerScriptService.

I am beginning to confuse myself now… I should have asked OP which script he or she was using. Above, two forum members had designed a LocalScript for the client-side version, and a Script for the server-side version.

2 Likes


What I have so far.
other people helped me with that.

You are missing a parenthesis at the end of line 1.

game.Players.PlayerAdded:Connect(function(player)
2 Likes

the first line of the code should be:

game.Players.PlayerAdded:Connect(function(player)

not

game.Players.PlayerAdded:Connect(function(player
2 Likes

am I supposed to have any other scripts?