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 7 years ago
local sweep = script.Parent

sweep.Touched:connect(function(player)
    local t = player.Parent.Torso
    if player:IsA("Part") and player.Name == "Torso" then
        local w = Instance.new("Weld")
        w.Parent = sweep
        w.Part0 = t
        w.Part1 = sweep
        w.C0 = t.CFrame:toObjectSpace(sweep.CFrame)
        wait(5)
        w:Destroy()
        wait(2)
    end
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?

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
7 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.

local Debris = game:GetService("Debris")
local Sweep = script.Parent

Sweep.Touched:Connect(function(Hit)
    -- Runs whenever Sweep touches something

    -- Check to see if it was a Player that got Hit
    local HumanoidRootPart

    repeat
        Hit = Hit.Parent
        HumanoidRootPart = Hit:FindFirstChild("HumanoidRootPart")
    until HumanoidRootPart or Hit == workspace

    if HumanoidRootPart then
        local Weld = Instance.new("Weld")       
        Weld.Part0 = HumanoidRootPart
        Weld.Part1 = Sweep
        Weld.C0 = HumanoidRootPart.CFrame:toObjectSpace(Sweep.CFrame)
        Weld.Parent = Sweep

        Debris:AddItem(Weld, 5) -- Destroy the Weld Object in 5 seconds
    end
end)
Ad

Answer this question