I am scripting a gun script, I am making it so the gun follows the mouse in first person. I have the basics but it is extremely choppy and I have no idea what the problem is.
local player = game.Players.LocalPlayer
wait(.5)
OFFSET = Vector3.new(0, 1, 1)
local body = player.Character
local mouse = player:GetMouse()
r = false
--Aim Part--
function onmove()
body.Torso.Neck.C1 = CFrame.new()
body.Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((mouse.Hit.p - mouse.Origin.p).unit.y), 0, 0)
if body.Torso:FindFirstChild("RightArmWeld") ~= nil
then
if r == true
then
a = 0
local dif = body.Head.CFrame:toObjectSpace(script.Parent.Parent.Handle.CFrame).p + OFFSET
body.Torso.RightArmWeld.C1 = CFrame.new(dif)
end
new = (mouse.Hit.p - mouse.Origin.p).unit.y
x = -1.3
y = .5
z = .5
body.Torso:FindFirstChild("RightArmWeld").C1 = CFrame.new(x,y,z)*CFrame.Angles(-math.asin((mouse.Hit.p - mouse.Origin.p).unit.y)-1.7,0,0)
end
end
--
function ondown()
r = true
end
function onup()
r = false
end
mouse.Move:connect(onmove)
mouse.Button2Down:connect(ondown)
mouse.Button2Up:connect(onup)

17 comments
I mean the gun is weirdly placed, the camera is fine. But the guns rotation is great, just the position on the screen in fps moves around.
Does changing to RenderStepped affect anything?
nope
Do you have a place currently using this code? I don't understand the problem you're having.
mmmm Il open it http://www.roblox.com/Border-Conflict-Gun-Creation-place?id=180700657
Want it to be like http://www.roblox.com/Blackhawk-Rescue-Mission-1-Patch-v1-5-4-place?id=23973424 guns
Are the guns being just broken the problem you're having in your place?
No, They move... Go to the blackhawk rescue place and check there guns and compare to mine, trying to make them not move ;d
You misunderstand me. The camera in your place is permanently affixed to a specific spot when you use the gun.
Okay... No camera problem....... The gun I want to be a in a fixed place as well as rotate. It rotates but isnt fixed spot.
Can you upload a gfy of it? I can't get your place to work and I don't understand your problem at all.
go to http://www.roblox.com/Blackhawk-Rescue-Mission-MEGA-VIP-item?id=100737604 and see there gun. Its in a fixed spot at the lower right hand side of the screen, I want my gun to do that as well as point like theirs does. The problem is mine moves when you move the gun.
Do mean it, like, slides up and down your arm?
Yep
Are you able to move the gun up or down on the arm via some offset value, and have it stay fixed relative to the arm (not the camera)?
Yep! It already moves up and down but its not fixed :(
Gonna edit my answer really fast.