Altitorture System is laggy in-game (Rope Constraints)

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to achieve a system similar to Altitorture that attaches all players (not just 2) to each other. This works fine in studio, but in-game It’s rather laggy for a player. I don’t know how to fix this.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have - and I’ve tried using line forces, rope constraints, spring constraints, they’re all laggy. I’m really stumped on how to fix this.

Mostly It’s only laggy for one player and perfectly smooth for the other - in studio It’s not laggy at all. Here is my source code:

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local function CreateAttachment(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local rootPart = character:WaitForChild("HumanoidRootPart")

	local attachment = Instance.new("Attachment")
	attachment.Parent = rootPart
	attachment.Position = Vector3.new(0, 0, 0)

	return attachment
end

local ropeConstraint

local function CreateRopeConstraint(attachment1, attachment2)
	ropeConstraint = Instance.new("RopeConstraint")
	ropeConstraint.Parent = Workspace
	ropeConstraint.Attachment0 = attachment1
	ropeConstraint.Attachment1 = attachment2
	ropeConstraint.Thickness = 0.25
	ropeConstraint.Visible = true
	return ropeConstraint
end

local attachments = {}

local function ConnectPlayers()
	local players = Players:GetPlayers()

	for _, player in pairs(players) do
		local attachment = CreateAttachment(player)
		table.insert(attachments, attachment)
	end

	for i = 1, #attachments - 1 do
		CreateRopeConstraint(attachments[i], attachments[i + 1])
	end
end

--ConnectPlayers()

local attachment
local lastAttachment

Players.PlayerAdded:Connect(function(player)
	attachment = CreateAttachment(player)
	lastAttachment = attachments[#attachments]
	CreateRopeConstraint(lastAttachment, attachment)
	table.insert(attachments, attachment)
end)

for i, kp in pairs(workspace:GetDescendants()) do
	if kp:IsA("Part") and kp.Name == "KillPart" or kp.Name == "TransparentPart" then		
		local function TouchedFunction(Part)
			local Parent = Part.Parent			
			local Player = Players:GetPlayerFromCharacter(Parent)
			
			if Part.Name == "Ball" then
				
				local Explosion = Instance.new("Explosion", kp)
				Explosion.Position = kp.Position
				Explosion.BlastRadius = 0
				Explosion.BlastPressure = 0
				Explosion.TimeScale = 1
				
				Part.CanCollide = false
				TweenService:Create(Part, TweenInfo.new(0.25), {Position = Vector3.new(-412.259, 24, -0.5)}):Play()
				
				task.wait(0.25)
				
				Part.CanCollide = true
			end
			
			if Players:GetPlayerFromCharacter(Parent) then
				Player:LoadCharacter()
								
				for i, plr in pairs(Players:GetPlayers()) do
					ropeConstraint:Destroy()
					attachment:Destroy()
					lastAttachment:Destroy()
					
					local newAttachment = CreateAttachment(plr)
					local newLastAttachment = attachments[#attachments]
					CreateRopeConstraint(newLastAttachment, newAttachment)
					table.insert(attachments, newAttachment)
				end
			end
		end

		kp.Touched:Connect(TouchedFunction)
	end
end
2 Likes