Okay, i maked my own holster system for my melees - but, how to make more realistic jiggle physics for holsters? I don’t really know roblox physics based on this.
But I tried to do at least something to make it look realistic and this is what came out of it:
Holster system script (server)
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local character = player.Character
local backpack = player.Backpack
local holsters = {}
-- Function to update holsters based on the tools in the backpack
local function updateHolsters(tool)
for _, holsterTemplate in pairs(game.ReplicatedStorage.Holsters:GetChildren()) do
if holsterTemplate.Name == tool.Name .. "Holst" then
local holster = holsterTemplate:Clone()
holster.Parent = character
-- Set the CFrame based on the tool name
if tool.Name == "Zweinhander" then
local weld = script.ZweinhanderHolst:Clone()
weld.Parent = holster
weld.Part0 = character.Torso
weld.Part1 = holster.Grip
weld.Enabled = true
weld.Script.Enabled = true
elseif tool.Name == "Baseball Bat" then
local weld = script["Baseball BatHolst"]:Clone()
weld.Parent = holster
weld.Part0 = character.Torso
weld.Part1 = holster.Grip
weld.Enabled = true
weld.Script.Enabled = true
elseif tool.Name == "Katana" then
local weld = script["KatanaHolst"]:Clone()
weld.Parent = holster
weld.Part0 = character.Torso
weld.Part1 = holster.Grip
weld.Enabled = true
weld.Script.Enabled = true
end
-- Store the holster in the table
table.insert(holsters, holster)
break -- Exit the inner loop once we find the holster
end
end
end
-- Function to remove a holster when a tool is removed
local function removeHolster(tool)
for _, holster in pairs(holsters) do
if holster.Name == tool.Name .. "Holst" and not character:FindFirstChild(tool.Name) then
holster:Destroy()
table.remove(holsters, table.find(holsters, holster))
break -- Exit the loop once we find and remove the holster
end
end
end
for _, i in pairs(game.Players:GetPlayerFromCharacter(script.Parent).Backpack:GetChildren()) do
if i:IsA("Tool") then
updateHolsters(i)
end
end
-- Connect to the ChildAdded and ChildRemoved events to update holsters in real-time
backpack.ChildRemoved:Connect(removeHolster)
backpack.ChildAdded:Connect(function(i)
if i:FindFirstChild("Configuration") then
wait(tonumber(i.Configuration.UnequipTime.Value))
updateHolsters(i)
else
updateHolsters(i)
end
end)
This is what weld’s of holsters look like:
Holster system script (local)
local TweenService = game:GetService("TweenService")
local Humanoid = script.Parent.Parent.Parent.Humanoid
local deb = false
game["Run Service"].Heartbeat:Connect(function()
if Humanoid.Parent.HumanoidRootPart.Velocity.Magnitude > 3 and not deb then
deb = true
-- Создание первого Tween
if Humanoid.Parent.HumanoidRootPart.Velocity.Magnitude >= 20 then
local Tween4 = TweenService:Create(script.Parent, TweenInfo.new(0.25, Enum.EasingStyle.Sine), {
C1 = CFrame.Angles(math.rad(-20), math.rad(0), math.rad(20))
})
--game.ReplicatedStorage.Holster:FireServer(script.Parent,TweenInfo.new(0.25, Enum.EasingStyle.Sine),CFrame.Angles(math.rad(-20), math.rad(0), math.rad(20)))
Tween4:Play()
Tween4.Completed:Wait() -- Ожидание завершения первого Tween
-- Создание третьего Tween
local Tween6 = TweenService:Create(script.Parent, TweenInfo.new(0.25, Enum.EasingStyle.Sine), {
C1 = CFrame.Angles(math.rad(20), math.rad(0), math.rad(10))
})
-- game.ReplicatedStorage.Holster:FireServer(script.Parent,TweenInfo.new(0.25, Enum.EasingStyle.Sine),CFrame.Angles(math.rad(20), math.rad(0), math.rad(10)))
Tween6:Play()
Tween6.Completed:Wait() -- Ожидание завершения третьего Tween
deb = false
elseif Humanoid.Parent.HumanoidRootPart.Velocity.Magnitude >= 4 then
local Tween4 = TweenService:Create(script.Parent, TweenInfo.new(0.41, Enum.EasingStyle.Sine), {
C1 = CFrame.Angles(math.rad(-20), math.rad(0), math.rad(20))
})
--- game.ReplicatedStorage.Holster:FireServer(script.Parent,TweenInfo.new(0.41, Enum.EasingStyle.Sine),CFrame.Angles(math.rad(-20), math.rad(0), math.rad(20)))
Tween4:Play()
Tween4.Completed:Wait() -- Ожидание завершения первого Tween
-- Создание третьего Tween
local Tween6 = TweenService:Create(script.Parent, TweenInfo.new(0.41, Enum.EasingStyle.Sine), {
C1 = CFrame.Angles(math.rad(20), math.rad(0), math.rad(10))
})
-- game.ReplicatedStorage.Holster:FireServer(script.Parent,TweenInfo.new(0.41, Enum.EasingStyle.Sine),CFrame.Angles(math.rad(20), math.rad(0), math.rad(10)))
Tween6:Play()
Tween6.Completed:Wait() -- Ожидание завершения третьего Tween
deb = false
else
local Tween4 = TweenService:Create(script.Parent, TweenInfo.new(0.41, Enum.EasingStyle.Sine), {
C1 = CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
})
--game.ReplicatedStorage.Holster:FireServer(script.Parent,TweenInfo.new(0.41, Enum.EasingStyle.Sine),CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)))
Tween4:Play()
Tween4.Completed:Wait() -- Ожидание завершения первого Tween
deb = false
end
end
end)
And I wonder - how to make it visible to all players? So that they can also see it smoothly and without any load on the game (lags, etc.)
I will be very glad to hear from anyone who gives any comments or advice! (sry for my bad english if i maked so much errors in text lol)