01 | local sweep = script.Parent |
02 |
03 | sweep.Touched:connect( function (player) |
04 | local t = player.Parent.Torso |
05 | if player:IsA( "Part" ) and player.Name = = "Torso" then |
06 | local w = Instance.new( "Weld" ) |
07 | w.Parent = sweep |
08 | w.Part 0 = t |
09 | w.Part 1 = sweep |
10 | w.C 0 = t.CFrame:toObjectSpace(sweep.CFrame) |
11 | wait( 5 ) |
12 | w:Destroy() |
13 | wait( 2 ) |
14 | end |
15 | end ) |
I'm kind of new to this whole thing, but I'm not sure whether I'm using the CFrame wrong or I should use something different altogether.
What I want to do is make a sweeper that, when touched, grabs and holds the player at the point they touched it. Like if I touched it on the end of the sweeper, they would get stuck there.
Now, it instead moves the torso to the middle of the sweeper part. What do?
This should work better for you. The only problem you might have is that after the weld is destroyed, the touched event can happen again and replace it, so make sure there is an adequate debounce system.
01 | local Debris = game:GetService( "Debris" ) |
02 | local Sweep = script.Parent |
03 |
04 | Sweep.Touched:Connect( function (Hit) |
05 | -- Runs whenever Sweep touches something |
06 |
07 | -- Check to see if it was a Player that got Hit |
08 | local HumanoidRootPart |
09 |
10 | repeat |
11 | Hit = Hit.Parent |
12 | HumanoidRootPart = Hit:FindFirstChild( "HumanoidRootPart" ) |
13 | until HumanoidRootPart or Hit = = workspace |
14 |
15 | if HumanoidRootPart then |