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.
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)
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.