Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- repeat
- wait()
- until game:IsLoaded()
- local plr = game.Players.LocalPlayer
- local char = plr.Character
- local mouse = plr:GetMouse()
- local cam = workspace.CurrentCamera
- local User = game:GetService("UserInputService")
- local Run = game:GetService("RunService")
- local RS = game.ReplicatedStorage
- local GunModules = RS:WaitForChild("GunModules")
- local GunModels = RS:WaitForChild("GunModels")
- local Primary = "AK47"
- local WeaponInHand
- local LArm, RArm
- local WeaponData
- local aimming = false
- local maincf = CFrame.new() --weapon offset of camera
- local larmcf = CFrame.new() --left arm offset of weapon
- local rarmcf = CFrame.new() --right arm offset of weapon
- local aimcf = CFrame.new()
- User.MouseIconEnabled = false
- plr.CameraMode = Enum.CameraMode.LockFirstPerson
- Run.RenderStepped:Connect(function()
- if WeaponInHand and LArm and RArm then --Check if the weapon and arms are loaded
- WeaponInHand:SetPrimaryPartCFrame(
- cam.CFrame
- * maincf
- * aimcf
- )
- LArm:SetPrimaryPartCFrame(
- WeaponInHand.PrimaryPart.CFrame
- * larmcf
- )
- RArm:SetPrimaryPartCFrame(
- WeaponInHand.PrimaryPart.CFrame
- * rarmcf
- )
- if aimming then
- aimcf = aimcf:Lerp(WeaponData.AimCFrame,0.2) --Goal CFrame (lower the number, lower the speed is)
- else
- aimcf = aimcf:Lerp(CFrame.new(), 0.1)
- end
- end
- end)
- function setup(weapon)
- --setup weapon data module
- WeaponData = require(GunModules:WaitForChild(weapon))
- maincf = WeaponData.MainCFrame
- larmcf = WeaponData.LArmCFrame
- rarmcf = WeaponData.RArmCFrame
- --setup arms to camera
- LArm = RS:WaitForChild("Left Arm"):Clone()
- LArm.PrimaryPart = LArm:WaitForChild("Main")
- LArm.Parent = cam
- for i, part in pairs(LArm:GetChildren()) do
- if part:IsA("BasePart") then
- part.Anchored = true --Make all the parts anchored so it wont fall off
- part.CanCollide = false --make al the parts cant collide so the character wont fly
- end
- end
- RArm = RS:WaitForChild("Right Arm"):Clone()
- RArm.PrimaryPart = RArm:WaitForChild("Main")
- RArm.Parent = cam
- for i, part in pairs(RArm:GetChildren()) do
- if part:IsA("BasePart") then
- part.Anchored = true --Make all the parts anchored so it wont fall off
- part.CanCollide = false --make al the parts cant collide so the character wont fly
- end
- end
- --setup weapon to camera
- WeaponInHand = GunModels:WaitForChild(weapon)
- WeaponInHand.PrimaryPart = WeaponInHand:WaitForChild("Handle")
- WeaponInHand.Parent = cam
- for i, part in pairs(WeaponInHand:GetChildren()) do
- if part:IsA("BasePart")then
- part.Anchored = true --make all th parts anchored so it wont fall off
- part.CanCollide = false --make all the parts can't collide so the charcter won't fly
- end
- end
- end
- mouse.Button2Down:Connect(function()
- aimming = true
- end)
- mouse.Button2Up:Connect(function()
- aimming = false
- end)
- setup(Primary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement