How to add realistic jiggle physics for my holster system?

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.

ezgif-4-0e15ca1205(1)

But I tried to do at least something to make it look realistic and this is what came out of it:

ezgif-4-65fa9b558f(1)

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! :wink: (sry for my bad english if i maked so much errors in text lol)

1 Like

An alternative you could use is a BallSocketContraint and allow physics to do the work. Just be aware you may want to have a script SetNetworkOwnership of the sword object to the player holding it, and disable CanCollide on the object.

Granted, the current system you have in place sells the effect well enough. If you want it to work for all other players, allowing the character to have network ownership over the holstered item should work fine. You’re only risks are if someone exploits decides to mess with the holster. But as long as its no-collide, you shouldn’t have any issues. Performance also shouldn’t be a worry because Roblox already handles the Client → Server Physics Data well.

1 Like