Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Who can me help for a leaderboard and jumping script?

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

✓ Accepted answer

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)

8 comments

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.

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?

0

Once they jump and touch the ground.

0

Yea, ill make one rq, hold on

0

Ok tanks!

0

I've tried lots of things, I don't know how, sorry :/

0

No problem! Thank you very much for all your help!

0

No Problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.