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

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

Asked by 9 years ago

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)
0
Key down is depricated EzraNehemiah_TF2 3552 — 9y
0
It still works for me, but what else should I use? Ross1397 25 — 9y
0
Um. For a beginner, KeyDown works... When you get advanced use UserInputService EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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
Ad

Answer this question