I have a leader board set up and it works fine - I can see it when I test the game, yet I cannot find out how I would increase the stat for jumps made. Ex: I want the leader board to display how many jumps a player has made.
This is the current script: *note the commented part was just to make it easier to copy the code into different places
local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local jumps = Instance.new("IntValue") jumps.Name = "Jumps" jumps.Value = 0 jumps.Parent = leaderstats local level = Instance.new("IntValue") level.Name = "Level" level.Value = 0 level.Parent = leaderstats end game.Players.PlayerAdded:Connect(onPlayerJoin) --local character = script.Parent -- local humanoid = character:WaitForChild("Humanoid") -- local JumpCounter = 0 -- JumpCounter = jumps -- humanoid.Jumping:Connect(function() -- JumpCounter = JumpCounter + 1 -- end)
My question is how would I get it to count the jumps? Nothing I have tried so for has worked. Do I need to make a new script somewhere else? Or is keeping it in the PlayerSetup ok?
To achieve this, you just need to get the Character
from the player
object, which you have already obtained from the PlayerAdded
event.
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local jumps = Instance.new("IntValue") jumps.Name = "Jumps" jumps.Value = 0 jumps.Parent = leaderstats local level = Instance.new("IntValue") level.Name = "Level" level.Value = 0 level.Parent = leaderstats local DebounceTime = .5 local CanJump = true local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") humanoid:GetPropertyChangedSignal("Jump"):Connect(function() if humanoid.Jump == true and CanJump then jumps.Value = jumps.Value + 1 CanJump = false wait(DebounceTime) CanJump = true end end) end)
Inside of the Humanoid there is "Jump" so using the Changed function this can be done Accept answer if this helped``
local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local jumps = Instance.new("IntValue") jumps.Name = "Jumps" jumps.Value = 0 jumps.Parent = leaderstats local level = Instance.new("IntValue") level.Name = "Level" level.Value = 0 level.Parent = leaderstats end game.Players.PlayerAdded:Connect(onPlayerJoin) local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local JumpCounter = 0 JumpCounter = jumps humanoid.Jump.Changed:Connect(function() if humanoid.Jump == true then JumpCounter = JumpCounter + 1 elseif humanoid.Jump == false then print("ended") end end)