How come this doesn't have the intended effect?

This sample code doesn’t seem to work or have the intended effect. I’m trying to make a bullet eject from a specific part in the gun, but it just spawns inside the ejection part and drops. Help?


	local EjectionSpeed = 100

	local ShellCasing = game.ReplicatedStorage.GunStuff.Casings.ELY36Casing:Clone()
	local EjectionPort = script.Parent.EjectionPort
	

		ShellCasing:PivotTo(EjectionPort.CFrame)
		ShellCasing:ApplyImpulse(EjectionPort.CFrame.RightVector * EjectionSpeed)
	
		ShellCasing.Parent = workspace
	
	script.Parent.Handle.CasingDrop:Play()

It looks like the issue is with the line ShellCasing:PivotTo(EjectionPort.CFrame). The PivotTo method is not a built-in function in Roblox and is likely causing the code to fail.

Instead, you can try setting the CFrame of the shell casing to the CFrame of the ejection port and then applying an impulse to it in the direction you want it to eject. Here’s an updated version of the code:

local EjectionSpeed = 100

local ShellCasing = game.ReplicatedStorage.GunStuff.Casings.ELY36Casing:Clone()
local EjectionPort = script.Parent.EjectionPort

ShellCasing.CFrame = EjectionPort.CFrame
ShellCasing.Velocity = EjectionPort.CFrame.RightVector * EjectionSpeed

ShellCasing.Parent = workspace

script.Parent.Handle.CasingDrop:Play()

This should set the initial position of the shell casing to the position of the ejection port and then apply an impulse to it in the direction specified by the RightVector of the ejection port’s CFrame. You may need to adjust the EjectionSpeed value to achieve the desired effect.

PivotTo is a valid method for Models.