Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a sweeper that grabs people at the point they touched it?

Asked by 8 years ago
01local sweep = script.Parent
02 
03sweep.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.Part0 = t
09        w.Part1 = sweep
10        w.C0 = t.CFrame:toObjectSpace(sweep.CFrame)
11        wait(5)
12        w:Destroy()
13        wait(2)
14    end
15end)

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?

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

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.

01local Debris = game:GetService("Debris")
02local Sweep = script.Parent
03 
04Sweep.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
View all 24 lines...
Ad

Answer this question