Module breaks on respawn

Hi, I have a module, and when the character respawns there is a random chance that the module will break and will not work (the code completely works, it just breaks on respawn)

Module code:

game:GetService('RunService').Stepped:Wait()

local Tween = {}



function Tween.TweenWeld(TargetLimb, StartCFrame, CFrame0, EasingDirection, EasingStyle, Duration)
	
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Workspace = game:GetService("Workspace")

	local Storage = ReplicatedStorage:WaitForChild("Storage")
	local Modules = Storage:WaitForChild("Modules")
	local BridgeNet = require(Modules:WaitForChild("BridgeNet"))
	local EditLimb = BridgeNet.CreateBridge("EditLimb")

	local player = game:GetService("Players").LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	if character.Parent ~= Workspace then return end
	
	


	local Torso = character:WaitForChild("Torso")
	local Head = character:WaitForChild("Head")
	local RA = character:WaitForChild("Right Arm")
	local LA = character:WaitForChild("Left Arm")
	local RL = character:WaitForChild("Right Leg")
	local LL = character:WaitForChild("Left Leg")
	local Humanoid = character:WaitForChild("Humanoid")
	
	local TweenService = game:GetService("TweenService")
	local weldExists = false
	local weld = nil
	local appendiges = {RA, LA, RL, LL, Head}
	local correspondingJoints = {Torso:FindFirstChild("Right Shoulder"), Torso:FindFirstChild("Left Shoulder"), Torso:FindFirstChild("Right Hip"), Torso:FindFirstChild("Left Hip"), Torso:FindFirstChild("Neck")}

	local EndCFrame = {}
	EndCFrame.C0 = CFrame0

	local Info = TweenInfo.new(Duration, EasingStyle, EasingDirection)

	for _,v in pairs(Torso:GetChildren()) do
		if v.Name == "Weld" and v.Part1.Name == TargetLimb then
			weldExists = true
			weld = v
		end
	end

	if not weldExists then
		weld = Instance.new("Weld")
	end 

	for i,v in pairs(appendiges) do
		if TargetLimb == v.Name then
			correspondingJoints[i].Part1 = nil

			weld.Parent = Torso
			weld.Part0 = Torso
			weld.Part1 = v
			weld.C0 = StartCFrame
			local Animation = TweenService:Create(weld, Info, EndCFrame)
			Animation:Play()
			EditLimb:Fire("Tween" , TargetLimb, StartCFrame, CFrame0, EasingDirection, EasingStyle, Duration)
		end
	end
	
	Humanoid.Died:Connect(function()
		
	end)
end



return Tween

Any help would be appreciated, thanks!

1 Like

No errors in output? Would be unlikely to have no errors if something breaks.

1 Like
game:GetService('RunService').Stepped:Wait()

local Tween = {}



function Tween.TweenWeld(TargetLimb, StartCFrame, CFrame0, EasingDirection, EasingStyle, Duration)
	
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Workspace = game:GetService("Workspace")

	local Storage = ReplicatedStorage:WaitForChild("Storage")
	local Modules = Storage:WaitForChild("Modules")
	local BridgeNet = require(Modules:WaitForChild("BridgeNet"))
	local EditLimb = BridgeNet.CreateBridge("EditLimb")

	local player = game:GetService("Players").LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait() and player.Character
	
    -- if character.Parent ~= Workspace then return end
	
	


	local Torso = character:WaitForChild("Torso")
	local Head = character:WaitForChild("Head")
	local RA = character:WaitForChild("Right Arm")
	local LA = character:WaitForChild("Left Arm")
	local RL = character:WaitForChild("Right Leg")
	local LL = character:WaitForChild("Left Leg")
	local Humanoid = character:WaitForChild("Humanoid")
	
	local TweenService = game:GetService("TweenService")
	local weldExists = false
	local weld = nil
	local appendiges = {RA, LA, RL, LL, Head}
	local correspondingJoints = {Torso:FindFirstChild("Right Shoulder"), Torso:FindFirstChild("Left Shoulder"), Torso:FindFirstChild("Right Hip"), Torso:FindFirstChild("Left Hip"), Torso:FindFirstChild("Neck")}

	local EndCFrame = {}
	EndCFrame.C0 = CFrame0

	local Info = TweenInfo.new(Duration, EasingStyle, EasingDirection)

	for _,v in pairs(Torso:GetChildren()) do
		if v.Name == "Weld" and v.Part1.Name == TargetLimb then
			weldExists = true
			weld = v
		end
	end

	if not weldExists then
		weld = Instance.new("Weld")
	end 

	for i,v in pairs(appendiges) do
		if TargetLimb == v.Name then
			correspondingJoints[i].Part1 = nil

			weld.Parent = Torso
			weld.Part0 = Torso
			weld.Part1 = v
			weld.C0 = StartCFrame
			local Animation = TweenService:Create(weld, Info, EndCFrame)
			Animation:Play()
			EditLimb:Fire("Tween" , TargetLimb, StartCFrame, CFrame0, EasingDirection, EasingStyle, Duration)
		end
	end
	
	Humanoid.Died:Once(function()
		
	end)

end



return Tween

Nope, no errors in output at all.