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

Who can me help for a leaderboard and jumping script?

Asked by 1 year ago

Hey! I'm creating a game and I need help to do this: I first created a button where when we click on it the character jumps 8 meters. I also created a leaderboard. I would like to make that, when we click on the button, the leaderboard score increases by 1 and the character jumps 1 meter more. Theres the button script:

-- Parameters
local WAIT_TIME = .5

-- Services
Player = game:GetService("Players")

local button = script.Parent
local canActivate = true

local function playerJump()
    if canActivate then
        canActivate = false
        local localPlayer = Player.LocalPlayer
        local character = localPlayer.Character
        local Humanoid = character:WaitForChild("Humanoid")

        local oldJumpPower = Humanoid.JumpPower
        Humanoid.JumpPower = 100
        Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
        Humanoid.JumpPower = oldJumpPower

        task.wait(WAIT_TIME)
        canActivate = true
    end
end

button.Activated:Connect(playerJump)

And the leaderboard script:

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

    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = plr
    leaderstats.Name = "leaderstats"

    local JumpPower = Instance.new("IntValue")
    JumpPower.Value = 0
    JumpPower.Parent = leaderstats
    JumpPower.Name = "JumpPower"

end)

Thank you in advance for your answer! Cordially, Belox.

2 answers

Log in to vote
0
Answered by 1 year ago

This script both has leaderstats and datasave, should be what you need:

local ds = game:GetService("DataStoreService")
local data = ds:GetDataStore("Items")

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

    local leader = Instance.new("Folder")
    leader.Name = "leaderstats"
    leader.Parent = plr

    local JumpPower = Instance.new("NumberValue")
    JumpPower.Name = "JumpPower"
    JumpPower.Parent = leader

    local savedJumpPower = data:GetAsync(plr.UserId.."-JumpPower")

    if savedJumpPower then
        JumpPower.Value = savedJumpPower
    end

end)

game.Players.PlayerRemoving:Connect(function(plr)

    local suc, err = pcall(function()

        data:SetAsync(plr.UserId.."-JumpPower", plr.leaderstats.JumpPower.Value)

    end)

    if err then
        warn(err)
    end

end)
0
Thank you so much! I just have a small request, how can I do so that the score of the scoreboard does not increase until the character has not touched the ground because there could be cheaters! Thank you in advance for your answer! Sincerely, Belox. wDaerkfeX 37 — 1y
0
has or hasnt touched the ground, as in, once they jump and touch the ground, or once they jump, before they touch the ground? SubscribeToFeNiX 27 — 1y
0
Once they jump and touch the ground. wDaerkfeX 37 — 1y
0
Yea, ill make one rq, hold on SubscribeToFeNiX 27 — 1y
View all comments (4 more)
0
Ok tanks! wDaerkfeX 37 — 1y
0
I've tried lots of things, I don't know how, sorry :/ SubscribeToFeNiX 27 — 1y
0
No problem! Thank you very much for all your help! wDaerkfeX 37 — 1y
0
No Problem! SubscribeToFeNiX 27 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

There is an event that exists for the humanoid that fires whenever the player jumps. You could simply set up an event that utilizes Humanoid.Jumping to increase the leaderstat, or alternatively you could increase the leaderstat whenever the player clicks the button.

0
Ok I will try, thank you very much! wDaerkfeX 37 — 1y

Answer this question