This is a script that finds a weapon with a tag, duplicates its handle, and places it into the holster described in an attribute of that gun
I haven’t found a way to do an attribute for the offset though! Which means I have to manually check in the weld function what the guns name is to set the offset which is just extra work! But to get the orientation correct I must use the :FromOrientation() Function so I haven’t been able to find a better way, any help with this would be awesome
local collectionservice = game:GetService("CollectionService")
local function equiptoholster(tool, character, holster, offset)
local model = tool.Handle:Clone()
model.Name = tool.Name .." viewmodel"
model.Parent = holster
local cframe = CFrame.new(Vector3.new(0,2,0.75)) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(0))
local weld = Instance.new("Weld")
weld.Part0 = model
weld.Part1 = holster
if tool.Name == "1884 pin shot double barrel" then
cframe = CFrame.new(0.5,3.2,0) * CFrame.fromOrientation(math.rad(-90),math.rad(90),0)
elseif tool.Name == "1884 missouri river hawkin" then
cframe = CFrame.new(0, -0.5, 3) * CFrame.fromOrientation(0,0,0)
end
weld.C1 = cframe
weld.Parent = model
end
local function findHolster(v, character)
local holsterr = character:WaitForChild("holsterr")
local holsterl = character:WaitForChild("holsterl")
local backholster = character:WaitForChild("backholster")
if v:GetAttribute("holster") == "holsterr" then
equiptoholster(v, character, holsterl)
elseif v:GetAttribute("holster") == "holsterl" then
equiptoholster(v, character, holsterr)
elseif v:GetAttribute("holster") == "backholster" then
equiptoholster(v, character, backholster)
end
end
local function destroyViewmodel(v, character)
if character:FindFirstChild(v.Name .." viewmodel", true) then
character:FindFirstChild(v.Name .." viewmodel", true):Destroy()
end
end
collectionservice:GetInstanceAddedSignal("equiptoholster"):Connect(function(v)
local player = v.Parent.Parent
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local equipanimtrack = humanoid:LoadAnimation(v.equip)
if not character:FindFirstChild(v.Name .." viewmodel") then
findHolster(v, character)
end
player.Backpack.ChildRemoved:Connect(function(child)
if child.Name == v.Name then
equipanimtrack:Stop()
destroyViewmodel(v, character)
end
end)
v.Equipped:Connect(function()
v.Handle.holster:Play()
equipanimtrack:Play()
destroyViewmodel(v, character)
end)
v.Unequipped:Connect(function()
equipanimtrack:Stop()
findHolster(v, character)
end)
end)