I made it so when I right click with my gun it moves in front of my head. I want to make it so when I stop holding it teleports where it should be in the hand.
I tried saving the old position of the gun when I am aiming and then setting it back to the saved position when I stop holding click but if I move at all the gun will teleport where I was before.
I want to teleport the gun in a way where it is at the hand based on its grip maybe. Idk how. Also the game is R6.
local function OnInput(input :InputObject, processed)
if processed or not Equipped or OnCooldown then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
Aiming = true
while Aiming and Equipped do
if not OldPositon then
OldPositon = Handle.Position
end
local Head = Char.Head
Handle.Position = Head.Position
task.wait()
end
end
end
local function OnInputEnded(input :InputObject, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 and Equipped then
Aiming = false
if OldPositon then
Handle.Position = OldPositon
end
OldPositon = nil
end
end
UIS.InputEnded:Connect(OnInputEnded)
UIS.InputBegan:Connect(OnInput)
-- I didnt put the variables at the start in the script and the check if
-- it is equipped because they are not important for this