Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to add knockback for a gun?

So I need some help to make a gun that when you fire, it pushes you back or up a little.

1 comment

0

Request.

1 answer

I got it by detecting if you could see the gun part. Here is the code if anyone wants it!

script.Parent.Activated:Connect(function() local Camera = workspace.Camera local part = workspace.Gunn local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

if withinScreenBounds then
	local move = Instance.new("BodyVelocity")
	move.Parent = script.Parent.Parent.HumanoidRootPart
	move.Name = "Knockback"
	move.Velocity = Vector3.new(0,50,0)
	wait(0.5)
	move:Destroy()
end

end)

1 comment

0

Did that work? If so, mark it as solved. Else, let this post be continued.

This discussion is preserved as it was. New answers, comments, and votes are closed.