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

How can I make a part shoot a player?

Asked by 5 years ago

I made a part and gave it a mesh. Now all I need to do is make it shoot players. I have it set to following the player and always facing them. I just need it to shoot the player. Thank you in advance.

1 answer

Log in to vote
0
Answered by
RBLXNogin 187
5 years ago
Edited 5 years ago

Even though this isn't a request website, I have the nerve to awnser your question because My desire for reputation.The fact that you are asking this leads us to assume that you are new to scripting, in that case I will give you a script that makes a part move in a direction, and then give you wikia articles to help you. I will also give you a new awnser, and not go into anything advanced. Firstly, the shoot code.

local part = script.Parent --put this inside the part that you want to shoot.
while wait(.01) do
part.CFrame = part.CFrame + CFrame.new(x,y,z) -- Change X,Y,Z fitting on your needs. X is width, Y is height, and Z is debth. If you want it to go forward, then you might want to change the Z value and leave the others at 0 
end

I made a basic code that will make the part continuously shoot in any direction you choose. Anyways something in scripting is called > CFrame Values

A CFrame, short for** Coordinate Frame, is a data type used to rotate and position 3D objects**. As either an object property or a standalone unit, a CFrame contains global X, Y, and Z coordinates as well as rotation data for each axis. In addition, CFrames contain helpful functions for working with objects in the 3D space. https://developer.roblox.com/articles/Understanding-CFrame

Im pretty sure you do not just want something to be shot in a certain position (probally where the player is standing. My assumption is that you want it to shoot where the player's mouse is at. Using GetMouse() this becomes possible.

https://developer.roblox.com/api-reference/class/Mouse https://developer.roblox.com/api-reference/function/Player/GetMouse

ROBLOX has a tutorial that shows us how to make a lazer gun but it uses some advanced concepts called RayCasting, check it out

https://developer.roblox.com/articles/Making-a-ray-casting-laser-gun-in-Roblox

In conclusion this is how you can make your part shoot. But please note that you should really learn the basis of scripting before you try to do complex solutions. This problem is very easy to solve.

Thanks for listening! I know this helped so please accept my awnser if you believe this has set you in the right path.

Ad

Answer this question