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

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

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

✓ Accepted answer
local UIS = game:GetService("UserInputService")

if UIS:IsKeyDown(Enum.KeyCode.Space) then
	print("Space held!")
end

6 comments

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.

1

LocalScript

0

Any possible way to have it happen in a regular script?

0

No, UserInputService is client-side only. http://wiki.roblox.com/index.php?title=Userinputservice

0

Thanks.

0

You can see tho when the humanoid jumped but thats it

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