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)