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)
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
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)
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)
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.
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.
ServerScriptService would be the appropriate service, unless you are putting it on the client. If you are putting it on the client, yes, StarterPlayerScripts.
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.