Recently, I created a holster system and I’ve ran into one problem so far with the system. Whenever the player is tilted or sideways the part will move inside or move away from the character’s torso.
Normal view (Usually whenever the character is looking forward or walking straight)
Whenever you move sideways or just walk in any direction it will go in that direction but not stay on the back
Better example (GIF)
The code for the Holster System.
--> Services
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--> References
--> Tables
local ShealthController = {}
--> Configuration
local Enabled = true -- If false (broken or disabled) will not run.
--------------------------------
function ShealthController:HolsterWeapon(Character: Model, Sword: Tool)
if not Enabled then return warn(`[ReplicatedStorage/Modules/Shared/ShealthController]: ShealthController is currently disabled. (Did you mean to disable this?)`) end
if Character:FindFirstChild("HolsterGroup") then
Character:FindFirstChild("HolsterGroup"):Destroy()
end
local HolsterGroup = Instance.new("Folder")
HolsterGroup.Name = "HolsterGroup"
HolsterGroup.Parent = Character
local HolsterProp = ReplicatedStorage.Assets.Holster:FindFirstChild(Sword.Name):Clone()
HolsterProp.Name = "HolsterProp"
if HolsterProp.Transparency == 1 then HolsterProp.Transparency = 0 end
if Character:FindFirstChild("ArmorGroup") then
HolsterProp.CFrame = Character:WaitForChild("Torso").CFrame * CFrame.Angles(math.rad(90),math.rad(-40),0) - Vector3.zAxis*1
else
HolsterProp.CFrame = Character:WaitForChild("Torso").CFrame * CFrame.Angles(math.rad(90),math.rad(-40),0) - Vector3.zAxis*0.8
end
HolsterProp.Parent = HolsterGroup
local Weld = Instance.new("Weld")
Weld.Name = "HolsterWeld"
Weld.Part0 = HolsterProp
Weld.Part1 = Character:WaitForChild("Torso")
Weld.C1 = Character:WaitForChild("Torso").CFrame:Inverse() * HolsterProp.CFrame
Weld.Parent = HolsterProp
end
function ShealthController:UnholsterWeapon(Character: Model)
if not Enabled then return warn(`[ReplicatedStorage/Modules/Shared/ShealthController]: ShealthController is currently disabled. (Did you mean to disable this?)`) end
if Character:FindFirstChild("HolsterGroup") then
Character:FindFirstChild("HolsterGroup"):Destroy()
end
end
return ShealthController
Any help would be appreciated thank you!