Shoot out a part from humanrootpart when a key is pressed

i only have the key part but not quite the shooting part (btw i want the part to be cloned from replacted storage)

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Lol = game.Workspace.Lol

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E then
		--i guess this is where the shooting part goes
	end

did you mean like this?

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local pathToThePart = ReplicatedStorage.Part

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	if Key.KeyCode == Enum.KeyCode.E then
		--i guess you mean this
		local projectile = pathToThePart
		projectile.Parent = workspace
		projectile.CFrame = Player.Character.HumanoidRootPart.CFrame
		projectile.Velocity = camera.CFrame.LookVector * 10000
	end
end)
1 Like

how do i make it ancored when it touch a part?(btw ill be afking for a while)

You can use BasePart.Touched 30char

You could just assign a BodyVelocity object before you start the game, and set the MaxForce property to a high value then assign your Part like so:

local Part = game.ReplicatedStorage.PartToClone:Clone()
Part.Parent = workspace
Part.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.LookVector)
Part.BodyVelocity.Velocity = Part.CFrame.LookVector * 100

Part.Touched:Connect(function(Hit)
    if Hit.Parent == Player.Character then
        return
    end

    Part.Anchored = true
end)

The thing about the Velocity property is that it may not stay up & float all the way, which is why I usually go for a BodyVelocity object

Although thinking about it again you might need to assign the BodyVelocity on the client side to create it