Creating my own item asylum billy/dallas

The code works perfectly fine, its just laggy server-side. Id also like to make the body of it be pulled towards the connecting tentacle.
Here is the code:
`local currentarmsattached = 0
local endings = {}
for _, ending in script.Parent:GetChildren() do
if ending.Name == “Ending” then
table.insert(endings,ending)
end
end
function reachOut()
local ending = endings[math.random(1,#endings)]
if currentarmsattached >= 5 or ending.Reaching.Value == true then

else
	task.spawn(function()
		local raycast = workspace:Raycast(ending.Parent.HumanoidRootPart.Position,Vector3.new(math.random(-10,10),math.random(-5,25),math.random(-10,10)))
		if raycast then
			if raycast.Instance.Parent == script.Parent then

			else
				local pos = raycast.Position
				local detaching = false
				local finished = false
				currentarmsattached += 1
				ending.Reaching.Value = true
				local weld = Instance.new("WeldConstraint",ending)
				weld.Part0 = ending
				weld.Part1 = raycast.Instance
				local tween = game.TweenService:Create(ending,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Position = pos})
				tween:Play()
				task.spawn(function()
					repeat
						if (ending.Position - ending.Parent.HumanoidRootPart.Position).Magnitude >= 25 then
							weld:Destroy()
							ending.Reaching.Value = false
							currentarmsattached -= 1
							tween:Destroy()
							detaching = true
							continue
						end
						task.wait(0.05)
					until finished == true
				end)
				tween.Completed:Connect(function()
					finished = true
				end)
				task.wait(5)
				if detaching == false then
					repeat
						if math.random(1,3) == 1 then
							weld:Destroy()
							ending.Reaching.Value = false
							currentarmsattached -= 1
							detaching = true
						elseif math.random(1,3) == 2 then
							reachOut()
						else
							task.wait(15)
						end
					until detaching == true
				end
			end
		end
	end)
end

end
while task.wait(1) do
reachOut()
end`
Thanks in advace!
For anyone wondering, the object named “ending” is the end of the tentacles. Its what i use the raycasts for.

1 Like