I'm using Filtering Enabled so the script might be a little weird, the CFraming and everything should be the same as a regular script without Filtering Enabled. I'm new to CFrame and Vector3 still so this script doesn't really work. Basically it pastes itself and then only shoots in one area regardless of the position the character is facing. If you could please help that would be great!
local function PartShoot(player) local PartFolder = ServerStorage:FindFirstChild("Part") local Part = PartFolder:FindFirstChild("Part") local PartCopy = Part:Clone() local character = player.Character local movement = Instance.new("BodyVelocity",PartCopy) movement.velocity = Part.CFrame.lookVector movement.maxForce = Vector3.new(math.huge,math.huge,math.huge) --not working attempt part moves only forward, fix later PartCopy.Orientation = character["Right Arm"].Orientation PartCopy.Parent = character["Right Arm"] wait(3) PartCopy:Destroy() end
The bullet doesn't have any major speed yet because it only shoots in once direction and I needed to monitor which way it goes.
If anyone could help that would be fantastic! Thank you!
local function PartShoot(player) local PartFolder = ServerStorage:FindFirstChild("Part") local Part = PartFolder:FindFirstChild("Part") local PartCopy = Part:Clone() local character = player.Character local movement = Instance.new("BodyVelocity",PartCopy) movement.velocity = Part.CFrame.lookVector movement.maxForce = Vector3.new(math.huge,math.huge,math.huge) --not working attempt part moves only forward, fix later PartCopy.Orientation = character["Right Arm"].Orientation PartCopy.Parent = character["Right Arm"] wait(3) PartCopy:Destroy() end
I am first going to introduce to you Debris, it adds an object to Debris(and destroys it) after a given time so let's add that real quick:
local function PartShoot(player) local PartFolder = ServerStorage:FindFirstChild("Part") local Part = PartFolder:FindFirstChild("Part") local PartCopy = Part:Clone() game:GetService("Debris"):AddItem(PartCopy, 3) --This adds PartCopy to Debris and removes it after 3 seconds local character = player.Character local movement = Instance.new("BodyVelocity",PartCopy) movement.velocity = Part.CFrame.lookVector movement.maxForce = Vector3.new(math.huge,math.huge,math.huge) --not working attempt part moves only forward, fix later PartCopy.Orientation = character["Right Arm"].Orientation PartCopy.Parent = character["Right Arm"] end
Now for the 'juicy part' that you need, making the part go in the direction in which the player is looking, for that we can use a magical powers of CFraming. I will put it in the code and explain it:
local function PartShoot(player) local PartFolder = ServerStorage:FindFirstChild("Part") local Part = PartFolder:FindFirstChild("Part") local PartCopy = Part:Clone() game:GetService("Debris"):AddItem(PartCopy, 3) --This adds PartCopy to Debris and removes it after 3 seconds local character = player.Character local mouse = player:GetMouse() PartCopy.Orientation = character["Right Arm"].Orientation PartCopy.Parent = character["Right Arm"] PartCopy.CFrame = START CFRAME (Ex: handle.CFrame) --EDIT THIS PartCopy.CFrame = CFrame.new(START POSITION (Ex: handle.Position), mouse.Hit.p) --EDIT THIS TOO! local movement = Instance.new("BodyVelocity",PartCopy) movement.velocity = PartCopy.CFrame.lookVector * 90 movement.maxForce = Vector3.new(math.huge,math.huge,math.huge) end
Near the end of the script, it sets the CFrame/direction of the PartCopy, just edit the Start position/Start CFrame and you should be all set.
Also I supposedly fixed your broken movement part of the script.
Good luck!
You're doing some kinda weird things, but to just make the part shoot in the direction you're facing is pretty easy.
Currently, you're making the part shoot in the direction that it's facing. Part.CFrame.lookVector
All you need to do is change this to the direction that your head is facing. character.Head.CFrame.lookVector