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

How to replace mouse:Button1 with UserInputService Keypress properly?

Asked by 6 years ago
Edited 6 years ago

I have no idea how to pull this off properly. This right here is a dynamic jump that works when you hold down the left mouse button. I want the script to work with the space bar, not the left mouse button! Help!!!

local DRAIN_RATE = 15;
local RESTORE_RATE = 10;
local POWER = 14.5;

local Gui = require(script:WaitForChild("JetpackGui")).new();
local Energy = 100;
local Selected = false;
local Down = false;

local Player = game.Players.LocalPlayer;
local Character = Player.Character;
while Character==nil or Character:FindFirstChild("Humanoid")==nil or Character.Humanoid.Health==0 do
    wait();
    Character = Player.Character;
end

function onButton1Down()
    Down = true;
end

function onButton1Up()
    Down = false;
end

script.Parent.Selected:connect(function(mouse)
    Gui:Enable();
    mouse.Button1Down:connect(function() onButton1Down(mouse) end);
    mouse.Button1Up:connect(function() onButton1Up(mouse) end);
    Selected = true;
    while Selected do
        if Down then
            Energy = math.max(0, Energy - DRAIN_RATE);
            Gui:SetPercentage(Energy);
            local upVector = Character.HumanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(0, 1, 0));
            Character.HumanoidRootPart.Velocity = Character.HumanoidRootPart.Velocity + upVector * POWER;
            if Energy<=0 then
                Down = false;
            end
        else
            Energy = math.min(100, Energy + RESTORE_RATE);
            Gui:SetPercentage(Energy);
            if Energy >= 100 then Down = false; end
        end
        wait();
    end
end)

script.Parent.Deselected:connect(function(mouse)
    Gui:Disable();
    Selected = false;
end)

0
What? Your saying that you want the jump to only work when you hold left click, and saying that you want the jump to only work holding the spacebar? hiimgoodpack 2009 — 6y
0
you're*^ creeperhunter76 554 — 6y
1
too bad dont have time to add 2 extra characters hiimgoodpack 2009 — 6y
0
I just want the script to work when holding down the spacebar not when holding the click @hiimgoodpack JoeRaptor 72 — 6y

Answer this question