So im triying to make a gun system, and you know, you can aim guns.
HOW DO I DO THAT?
i searched every forum post and all the answers dont work.
PEASE BLESS ME WITH YOUR KNOWLEDGE
also here’s my place file if you wanna look
GunTest.rbxl (357.2 KB)
and the script:
Script Code
local arms = script:WaitForChild("armsViewmodel")
arms.Parent = workspace.CurrentCamera
local run = game:GetService("RunService")
local AimOffset = CFrame.identity
arms.ChildAdded:Connect(function(child: Instance)
local hand = child:FindFirstChild("HandleV")
if child.Name == "Model" and hand then
arms["Right Arm"].RightGrip.Part1 = hand
arms["Right Arm"].RightGrip.C0 = child:GetAttribute("Grip")
offset = arms.HumanoidRootPart.CFrame:ToObjectSpace(arms.Model.Aim.CFrame:Inverse())
end
end)
arms.ChildRemoved:Connect(function(child: Instance)
local hand = child:FindFirstChild("HandleV")
if child.Name == "Model" and hand then
arms["Right Arm"].RightGrip.Part1 = nil
end
end)
local function DivideCFrame(CF:CFrame,ammount)
local position = CF.Position
local x,y,z = CF:ToOrientation()
return CF.Rotation + (CF.Position / ammount)
end
local oldC1 = arms.HumanoidRootPart.Torso.C0
game.Players.LocalPlayer:GetMouse().Button2Down:Connect(function()
print(offset)
arms.HumanoidRootPart.Torso.C0 = offset or CFrame.identity
end)
game.Players.LocalPlayer:GetMouse().Button2Up:Connect(function()
arms.HumanoidRootPart.Torso.C0 = oldC1
end)
run.RenderStepped:Connect(function(deltaTime: number)
arms:PivotTo(game.Players.LocalPlayer.Character.Head.CFrame)
for _,v in arms:GetChildren() do
if v:IsA("BasePart") then
v.CanCollide = false
v.CanQuery = false
v.CanTouch = false
end
end
end)