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

Is it possible to detect if or when a humanoid is pressing/holding SpaceBar not in a LocalScript?

Asked by 6 years ago

So I've been doing some tests with scripts and stuff to make a Jetpack that goes upward when you hold down SpaceBar.

v Here's my unfinished script v

db = true
script.Parent.Touched:connect(function(h)

    human = h.Parent:FindFirstChild("Humanoid") 
    torso = h.Parent:FindFirstChild("Torso")

if human ~= nil then
    if torso ~= nil then
        if db == true then      
        db = false                      

        local upward = Instance.new("BodyForce", torso)     
        upward.Name = "Y_Acess"

        -- Possible function to have in here that detects when or if space was held down?           
        upward.Force = Vector3.new(0, 2100, 0)
        -- and elseif it wasn't being pressed or help down it would go to
        --upward.Force = Vector3.new(0, 0, 0)

        end -- db   
        wait(10000)
        db = true   
    end
end


end)

Hopefully, there should be a type of way to do this because I've used keyboard input functions before, but it was in a LocalScript.

Could somebody tell me if there's any possible way to have a keyboard input in a regular Script and not a LocalScript?

Thanks, -jack8699

1 answer

Log in to vote
0
Answered by 6 years ago
local UIS = game:GetService("UserInputService")

if UIS:IsKeyDown(Enum.KeyCode.Space) then
    print("Space held!")
end
0
Is that supposed to work in a regular script in workspace, or in a LocalScript? I tried doing that in the regular script and nothing happened. jack8699 15 — 6y
1
LocalScript Gey4Jesus69 2705 — 6y
0
Any possible way to have it happen in a regular script? jack8699 15 — 6y
0
No, UserInputService is client-side only. http://wiki.roblox.com/index.php?title=Userinputservice Gey4Jesus69 2705 — 6y
View all comments (2 more)
0
Thanks. jack8699 15 — 6y
0
You can see tho when the humanoid jumped but thats it Timmerman73 85 — 6y
Ad

Answer this question