I am sorry if this is posted in the wrong place, please let me know and I can change the location!
The title doesn’t really explain what I want, so here is what I want:
Recently I’ve been trying to make an action that picks up a player closest to the person activating the event, the player actually interferes with the animations after being welded. There are animations, they are just not happening because of the player glitching, or the rig glitching, I cannot tell which.
I already have something that turns cancollide to false and massless to true. But it still makes the animations very glitchy:
Here is my code, I am not a very experienced coder so please correct me if I am wrong:
local Event = script:WaitForChild("GrabEvent")
local Torso = script.Parent:WaitForChild("Torso")
local Animation = script:WaitForChild("RedEat")
local Anim = script.Parent.Humanoid:LoadAnimation(Animation)
function GetNearest(Pos)
local MaxDis = 50
local DistanceTable = {}
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character then
local Distance = v:DistanceFromCharacter(Pos)
if Distance < MaxDis then
table.insert(DistanceTable,{v,Distance})
end
end
end
table.sort(DistanceTable,
function(a,b)
return a[2] > b[2]
end
)
return DistanceTable
end
Event.OnServerEvent:Connect(function()
local PlrTable = GetNearest(Torso.Position)
local Closest = PlrTable[#PlrTable - 1]
local Character = Closest[1].Character
if Character then
Character.Torso.Anchored = true
Character.Torso.CFrame = script.Parent.RUpperHand.CFrame + Vector3.new(0, 0, 0)
Character.Torso.Orientation = Vector3.new(0, 90, 0)
local NewWeld = Instance.new("Weld")
NewWeld.Part0 = script.Parent.RUpperHand
NewWeld.Part1 = Character.Torso
NewWeld.C0 = script.Parent.RUpperHand.CFrame:Inverse()
NewWeld.C1 = Character.Torso.CFrame:Inverse()
NewWeld.Parent = Character.Torso
Character.Torso.Anchored = false
for i, v in pairs(Character:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = false
v.Massless = true
end
end
Character.HumanoidRootPart.CanCollide = false
wait(0.5)
Anim:Play(0.5)
wait(3)
NewWeld:Destroy()
wait(0.1)
Character.Humanoid.Health = 0
else
end
end)
I want to make it so it does not glitch and does the animations smoothly. I can’t find anything online to help me since I think it’s very specific.
Another thing I should mention, this is a custom rig, and I am not great at custom rigs so it could also be a problem
If you have any idea on how to fix this I’d love help!