How would I go about making a view model shoot?

I already know how to make a view model, my only problem is making it shoot. My only idea right now is cloning the character of the player, parenting it to the camera, aligning it with the player in the camera, and play the same animations in both the actual player and the view model player but making the actual gun shoot out a ray. Though, I have no idea if this would work or be practical at all :confused:

Alright so, i’ve been testing some things, this may be what you are looking for, you can tweak it to your liking if it is, if not let me know and i’ll be happy to help you find the proper solution!

local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	local Ray = Ray.new(Player.Character.Head.CFrame.p, (Mouse.Hit.p - Player.Character.Head.CFrame.p).Unit * 1000)
	local Hit, Pos = workspace:FindPartOnRay(Ray)

	if Hit then
		local Part = Instance.new("Part", workspace)
		Part.Name = "RayPart"
		Part.Transparency = 0
		Part.Anchored = true
		Part.BrickColor = BrickColor.new("Really red")
		Part.Material = Enum.Material.Neon
		Part.CanCollide = false
		Part.CFrame = CFrame.new(Player.Character.Head.CFrame.p, Pos) * CFrame.new(0, 0, -(Player.Character.Head.CFrame.p - Pos).Magnitude/2)
		Part.Size = Vector3.new(0.2, 0.2, (Pos - Player.Character.Head.CFrame.p).Magnitude)
		game.Debris:AddItem(Part, 0.5)

	end
end)
1 Like

this is a solution for making a gun shoot in the workspace, what I want is to make a gun in a view model, which is parented to the camera, be able to shoot a bullet that goes from the barrel of the gun, to the target.

Yes, alright, so what you’d do with the script I provided you is (assuming you have your gun fully scripted already), put the script I provided under your Ray.new function, and change the CFrame from

CFrame.new(Player.Character.Head.CFrame.p, Pos) * CFrame.new(0, 0, (Player.Character.Head.CFrame.p - Pos).Magnitude/2) to:

CFrame.new(Barrel.CFrame.p, Pos) * CFrame.new(0, 0, (Barrel.CFrame.p - Pos).Magnitude/2) and the Part.Size to:

Part.Size = Vector3.new(0.2, 0.2, (Pos - Barrel.CFrame.p).Magnitude).

I hope this solves your issue!

1 Like

Hello! Sorry for not responding in like 2 weeks, as I lost motivation on working on this project but, im back now and sorry again. So I tested this out, and this happened

https://streamable.com/qk065n

I dont know whats wrong, and im pretty sure I did everything right. Also the first half of the clip shows me clicking while the script is normal, then the second half i clicked without the negative sign as shown in the video.