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

How to make a hopperbin fire a rocket after a key press?

I'm new to scripting, so I'm just testing out some different types of tools. The tool I'm currently trying to make is a hopperbin that has multiple uses. So far, I've got most of it done, I just need to make it fire a rocket when the user presses the e key. Does anyone mind teaching me how to do this?

The code below is what I have so far:

function onKeyDown(key)
key:lower()
	if key == "e" then

end

function onSelected(mouse)
mouse.KeyDown:connect(onKeyDown)
end

script.Parent.Selected:connect(onSelected)

3 comments

0

Key down is depricated

0

It still works for me, but what else should I use?

0

Um. For a beginner, KeyDown works... When you get advanced use UserInputService

1 answer

Assuming your rocket is a single part in Wokspace named "Engine", or a group of parts welded to it:

function onKeyDown(key)
	key:lower()
        if key == "e" then  
		if Workspace.FindFirstChild("Engine") then
			Workspace.Engine.Velocity = Vector3.new(0,100,0);
		end
	end
end

function onSelected(mouse)
mouse.KeyDown:connect(onKeyDown)
end

script.Parent.Selected:connect(onSelected)

That will fling the part into the air with minimal code, but if you want continuous controllable thrust, look into BodyThrust on the wiki.

Hope this helps!

--Cantos

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