Theres something wrong with my tweening and i dont know what it is

hi, so i am a beginner scripter, and this is my first time tweening a part. this script i made wont run, and i am clueless on what the problem is. all i know is that the problem lies between the onserverevent connection and the ragdollcharacter custom function. there are other scripts connected to this, but i am 100% sure that its this script; ive tested the others and they work fine.

script (server):

ClientEvent.OnServerEvent:Connect(function(Plr, Char)
			if true then
				while task.wait() do
					for _, Thing in pairs(workspace:GetChildren()) do
						if Thing.Name == "LeftArmAttachment" then
							Thing.Touched:Connect(function(OtherPart)
								if true and CanTouch == true and OtherPart == Char:WaitForChild("Head") or OtherPart == Char:WaitForChild("Left Arm") or OtherPart == Char:WaitForChild("Right Arm") or OtherPart == Char:WaitForChild("Torso") or OtherPart == Char:WaitForChild("Left Leg") or OtherPart == Char:WaitForChild("Right Leg") then
									CanTouch = false
									
									local Impact           = math.random(5, 50)
									local ImpactGoal       = {Position = Thing.CFrame * Vector3.new(Thing.CFrame.LookVector.X * Impact, Thing.CFrame.LookVector.Y * Impact, 0) + Thing.Position}
									local ImpactTweenInfo  = TweenInfo.new(Impact / 20, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)
									local ImpactTween      = game:GetService("TweenService"):Create(OtherPart, ImpactTweenInfo, ImpactGoal)
									
									Ragdoll.RagdollCharacter(Char)
									ImpactTween:Play()
									
									workspace.RightBarrier.Touched:Connect(function(OtherPart2)
										if true and OtherPart2 == Char:WaitForChild("Head") or OtherPart2 == Char:WaitForChild("Left Arm") or OtherPart2 == Char:WaitForChild("Right Arm") or OtherPart2 == Char:WaitForChild("Torso") or OtherPart2 == Char:WaitForChild("Left Leg") or OtherPart2 == Char:WaitForChild("Right Leg") then
											ImpactTween:Cancel()
										end
									end)
									
									workspace.LeftBarrier.Touched:Connect(function(OtherPart3)
										if true and OtherPart3 == Char:WaitForChild("Head") or OtherPart3 == Char:WaitForChild("Left Arm") or OtherPart3 == Char:WaitForChild("Right Arm") or OtherPart3 == Char:WaitForChild("Torso") or OtherPart3 == Char:WaitForChild("Left Leg") or OtherPart3 == Char:WaitForChild("Right Leg") then
											ImpactTween:Cancel()
										end
									end)
									
									task.wait(0.2)
									
									workspace.Baseplate.Touched:Connect(function(OtherPart4)
										if true and OtherPart4 == Char:WaitForChild("Head") or OtherPart4 == Char:WaitForChild("Left Arm") or OtherPart4 == Char:WaitForChild("Right Arm") or OtherPart4 == Char:WaitForChild("Torso") or OtherPart4 == Char:WaitForChild("Left Leg") or OtherPart4 == Char:WaitForChild("Right Leg") then
											ImpactTween:Cancel()
										end
									end)

									CanTouch = true
									
									ImpactTween.Completed:Connect(function()
										if true then
											ImpactTween:Cancel()
										end
									end)
								end
							end)
						end
					end
				end
			end
		end)

for some reason its spaced incorrectly but whatever

sorry for the messy and unethical code, again, i am a beginner scripter. also, im not even scripting in my own style here, as this script was originally from a ragdoll module that i found via youtube tutorial, as i have no clue how to make my own ragdoll and this one seems to work really well, and i wanted the code to look like it was made by one person, so i coded in the style of the person who made the script originally.

anyway, other than where its happening, i have no clue whats going wrong. its probably something really obvious to a professional since im so new to scripting, but i cant see whats wrong with the script. please help

edit: i shouldve provided more info, theres more info in the 2nd and 3rd replies (3rd and 4th post messages)

1 Like

Is there an object that is named LeftArmAttachment parented to workspace? If there is, what ClassName is it?

Is your character R15? It could be why it doesn’t work, it explicitly checks for R6 body parts
And a bunch of more things like CanTouch, etc. There’s too many inaccuracies and questions here

i prob shouldve cleared this up, but my character is R6 and CanTouch is a boolean variable that acts as a debounce. and yes, a part (basepart, a regular part) appears in the workspace (cloned from replicatedstorage) that is named “LeftArmAttachment” when the player presses E or a button on mobile. this will be adjusted for it to only be the players who arent chosen (via randomizer) but for now it appears whenever anyone presses E/a button. this is also scripted on the server

also, Ragdoll.RagdollCharacter(Char) comes from a ragdoll module that i did not make

You can’t tween parts using TweenService. It only tweens if you use :Lerp()

Is the part anchored? You can’t tween unanchored parts
@Earthraphobic2 You can tween parts by the way, but it must be anchored. Lerp is way more complicated

1 Like

i see, the “OtherPart” normally isnt anchored. i tried anchoring the HumanoidRootPart and tweening that instead, but it still didnt work. what am i doing wrong?

new code:

ClientEvent.OnServerEvent:Connect(function(Plr, Char)
			if true then
				while task.wait() do
					for _, Thing in pairs(workspace:GetChildren()) do
						if Thing.Name == "LeftArmAttachment" then
							Thing.Touched:Connect(function(OtherPart)
								if true and CanTouch == true and OtherPart == Char:WaitForChild("Head") or OtherPart == Char:WaitForChild("Left Arm") or OtherPart == Char:WaitForChild("Right Arm") or OtherPart == Char:WaitForChild("Torso") or OtherPart == Char:WaitForChild("Left Leg") or OtherPart == Char:WaitForChild("Right Leg") then
									CanTouch = false
									Char:WaitForChild("HumanoidRootPart").Anchored = true
									
									local Impact           = math.random(5, 50)
									local ImpactGoal       = {Position = Thing.CFrame * Vector3.new(Thing.CFrame.LookVector.X * Impact, Thing.CFrame.LookVector.Y * Impact, 0) + Thing.Position}
									local ImpactTweenInfo  = TweenInfo.new(Impact / 20, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)
									local ImpactTween      = game:GetService("TweenService"):Create(Char.HumanoidRootPart, ImpactTweenInfo, ImpactGoal)
									
									Ragdoll.RagdollCharacter(Char)
									ImpactTween:Play()
									
									workspace.RightBarrier.Touched:Connect(function(OtherPart2)
										if true and OtherPart2 == Char:WaitForChild("Head") or OtherPart2 == Char:WaitForChild("Left Arm") or OtherPart2 == Char:WaitForChild("Right Arm") or OtherPart2 == Char:WaitForChild("Torso") or OtherPart2 == Char:WaitForChild("Left Leg") or OtherPart2 == Char:WaitForChild("Right Leg") then
											ImpactTween:Cancel()
											Char.HumanoidRootPart.Anchored = false
										end
									end)
									
									workspace.LeftBarrier.Touched:Connect(function(OtherPart3)
										if true and OtherPart3 == Char:WaitForChild("Head") or OtherPart3 == Char:WaitForChild("Left Arm") or OtherPart3 == Char:WaitForChild("Right Arm") or OtherPart3 == Char:WaitForChild("Torso") or OtherPart3 == Char:WaitForChild("Left Leg") or OtherPart3 == Char:WaitForChild("Right Leg") then
											ImpactTween:Cancel()
											Char.HumanoidRootPart.Anchored = false
										end
									end)
									
									task.wait(0.2)
									
									workspace.Baseplate.Touched:Connect(function(OtherPart4)
										if true and OtherPart4 == Char:WaitForChild("Head") or OtherPart4 == Char:WaitForChild("Left Arm") or OtherPart4 == Char:WaitForChild("Right Arm") or OtherPart4 == Char:WaitForChild("Torso") or OtherPart4 == Char:WaitForChild("Left Leg") or OtherPart4 == Char:WaitForChild("Right Leg") then
											ImpactTween:Cancel()
											Char.HumanoidRootPart.Anchored = false
										end
									end)

									CanTouch = true
									
									ImpactTween.Completed:Connect(function()
										if true then
											ImpactTween:Cancel()
											Char.HumanoidRootPart.Anchored = false
										end
									end)
								end
							end)
						end
					end
				end
			end
		end)

edit: just realized, anchoring the HumanoidRootPart doesnt work, so it may not actually be my tweening

yeah, turns out, the localscript calling the remoteevent didnt have access to the character. it works now; very buggy, but i can fix it. still not marking this as the solution tho, as i didnt know tweened parts have to be anchored

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