making something and basically i have it where i bind the characters arms onto the camera to basically be a “viewmodel” for the guns.
as of right now it is its own script. i have plans to move it it elsewhere but not sure which option would be better.
Option 1:
Move the code into the guns themselves, having it bind the arms on equip and unbind them on unequip.
Option 2:
Move the code into the player’s main localscript. detecting if a gun is equipped then binding the arms.
Just wondering which one of these would be the better route.
The Uninteresting code
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RunService = game:GetService("RunService")
repeat task.wait() until game:IsLoaded()
repeat task.wait() until Character:IsDescendantOf(workspace)
-- Variables --
local Binded = false
local FTorso
local DebugMovementDelay = false
local DebugMovementDelayNum = 1
local BindRenderStep
local BindCoroutine
-- --
local RightUpperArm = Character:WaitForChild("RightUpperArm")
local LeftUpperArm = Character:WaitForChild("LeftUpperArm")
local RightArmMotor = Character:WaitForChild("RightUpperArm"):WaitForChild("RightShoulder")
local LeftArmMotor = Character:WaitForChild("LeftUpperArm"):WaitForChild("LeftShoulder")
local UpperTorso = Character:WaitForChild("UpperTorso")
local function BindArms()
if not Binded then
Binded = true
FTorso = Instance.new("Part")
FTorso.Anchored = true
FTorso.CanCollide = false
FTorso.CanQuery = false
FTorso.CanTouch = false
FTorso.Transparency = .7
FTorso.CastShadow = false
FTorso.Size = Vector3.new(
Character.UpperTorso.Size.X,
math.floor((Character.UpperTorso.Size.Y + Character.LowerTorso.Size.Y)),
Character.UpperTorso.Size.Z
)
FTorso.Parent = workspace.Camera
FTorso.Name = "UpperTorso"
RightArmMotor.Part0 = FTorso
LeftArmMotor.Part0 = FTorso
RightArmMotor.C0 = CFrame.new(RightArmMotor.C0.Position)-- * CFrame.Angles(math.rad(90),0,0)
RightArmMotor.C1 = CFrame.new(RightArmMotor.C1.Position)
LeftArmMotor.C0 = CFrame.new(LeftArmMotor.C0.Position)-- * CFrame.Angles(math.rad(90),0,0)
LeftArmMotor.C1 = CFrame.new(LeftArmMotor.C1.Position)
if DebugMovementDelay then
BindCoroutine = coroutine.create(function()
while task.wait(DebugMovementDelayNum) do
FTorso.CFrame = workspace.CurrentCamera.CFrame * CFrame.new(0,-1.8,-.5)
--FTorso.CFrame = CFrame.new(0,10,0)
end
end)
coroutine.resume(BindCoroutine)
else
BindCoroutine = coroutine.create(function()
BindRenderStep = RunService.RenderStepped:Connect(function()
FTorso.CFrame = workspace.CurrentCamera.CFrame * CFrame.new(0,-1.8,-.5)
--FTorso.CFrame = CFrame.new(0,10,0)
end)
end)
coroutine.resume(BindCoroutine)
end
else
warn("Arms already binded")
end
end
local function UnbindArms()
if Binded then
if FTorso then FTorso:Destroy() end
BindRenderStep:Disconnect()
coroutine.close(BindCoroutine)
RightArmMotor.Part0 = UpperTorso
LeftArmMotor.Part0 = UpperTorso
RightArmMotor.C0 = CFrame.new(RightArmMotor.C0.Position)
RightArmMotor.C1 = CFrame.new(RightArmMotor.C1.Position)
LeftArmMotor.C0 = CFrame.new(LeftArmMotor.C0.Position)
LeftArmMotor.C1 = CFrame.new(LeftArmMotor.C1.Position)
end
end
BindArms()