Character freezing when first attached to constraint

Hello. I am making a basketball game and I made a system where you can dunk and you have a chance to stay on the rim.

The system was originally on the server, but was moved to the client. When I moved it to the client, I started experiencing this issue where it’d attach my character but it would freeze anything physics related for about half a second.
Link to issue

Not sure if this is linked to a ROBLOX related physics issue, or an issue on my part.

Main attach code:

function HangInfo:AttachToRim(Goal, ClosestAttach, HandType, Handedness)
	Root.RootPriority = 150
	Humanoid.PlatformStand = true
	-- // Variables
	local Rim = Goal.Parent.Rim
	local AttachPart = ClosestAttach.Parent
	-- // Constraints
	-- Ball socket
	local BISConst = Instance.new("BallSocketConstraint", Rim)
	BISConst.Name = "RimHangConstraint"
	BISConst.LimitsEnabled = true
	BISConst.TwistLimitsEnabled = true
	BISConst.Restitution = .125
	BISConst.UpperAngle = 20
	BISConst.TwistUpperAngle = 65
	BISConst.TwistLowerAngle = -BISConst.TwistUpperAngle
	
	-- // Attachments
	local RootAttach = Instance.new("Attachment", Root)
	RootAttach.Name = "RimHang"
	if HandType == "OneHand" then 
		local Vector = Handedness == "R" and Vector3.new(0,2.5,-1.2) 
			or Vector3.new(0,2.5,-1.2)	
		RootAttach.Position = RootAttach.Position + Vector
	else
		RootAttach.Position = RootAttach.Position + Vector3.new(0,3.05,-.5)
	end
	--RootAttach.Visible = true

	-- // Finalize
	-- Orientation
	local PartAngle = tonumber(AttachPart.Name:sub(8,10))
	RootAttach.Orientation = Vector3.new(0,-PartAngle,0)
	-- Attach
	BISConst.Attachment0 = RootAttach; BISConst.Attachment1 = ClosestAttach
	print("Real att")
end

function HangInfo:UnAttachRim(Rim)
	-- // Reset
	Humanoid.PlatformStand = false
	-- // Clear
	-- Rim
	for _, Instance in pairs(Rim:GetChildren()) do
		if not StringUtil.find(Instance.Name, "RimHang") then
			continue
		end
		Instance:Destroy()
	end
	-- Root
	for _, Instance in pairs(Root:GetChildren()) do
		if not StringUtil.find(Instance.Name, "RimHang") then
			continue
		end
		Instance:Destroy()
	end
end

function HangInfo:RimHang(Goal, HangTime, DunkType, HandType, Handedness)
	-- // Variables
	local Rim = Goal.Parent.Rim
	local RimController = Rim.HingeConstraint
	-- // Point setup
	local Points = {}
	-- Set points
	for Angle = 0, 180, 10 do
		-- Create point
		local Radius = (Rim.Size.Z/2.2)
		local X,Z = self:GetPointPos(Radius, Angle)
		local Pos = Goal.CFrame.Position + Vector3.new(X,.7,Z)
		Pos = self:GetPointOrienPos(Goal, Pos)
		local Point = self:SpawnPoint(Goal, Angle, Pos, false)
		-- Log point
		table.insert(Points, {
			["Part"] = Point,
			["Distance"] = (Point.Position - Root.Position).Magnitude
		})
	end
	-- Get closest point
	table.sort(Points, function(a,b) 
		return a.Distance < b.Distance
	end)
	for Index, Point in pairs(Points) do
		if Index ~= 1 then
			Point.Part:Destroy()
			continue
		end
	end
	-- // Hang setup
	local ClosestPoint = Points[1].Part
	local ClosestAttach = ClosestPoint:FindFirstChild("Attachment")
	-- Animation
	local HangAnimation = AnimationModule:Get(Player,HandType.."RimHang")
	if DunkType == "Reverse" then
		HangAnimation = AnimationModule:Get(Player,DunkType.."RimHang")
	else
		if HandType == "OneHand" then
			HangAnimation = AnimationModule:Get(Player,"R"..HandType.."RimHang")
		else
			local HangString = HangAnimation.Name:sub(0,HangAnimation.Name:len()-1)
			local MaxAnim = AnimationModule:GetNumOfAnimsInSection(HangString)
			local RandAnim = Random.new():NextInteger(1,MaxAnim)
			HangAnimation = AnimationModule:Get(Player,HandType.."RimHang"..RandAnim)
		end
	end
	HangAnimation:Play(.25)
	HangAnimation:AdjustSpeed(0)
	-- Run
	self:AttachToRim(Goal,ClosestAttach,HandType,Handedness)
	-- Reset
	task.delay(HangTime, function()
		self:UnAttachRim(Rim)
		HangAnimation:Stop(.25)
	end)
end

-- // Event
Remotes.Hang.OnClientEvent:Connect(function(Goal, HangTime, DunkInfo)
	HangInfo:RimHang(Goal,HangTime, DunkInfo.DunkType, DunkInfo.HandType, DunkInfo.Handedness)
end)

It was being initiated too far away so the constraint would have to teleport / freeze to catch up.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.