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

Can I make FindPartsInRegion3 scan around torso everytime I activate it?

Asked by
z_lm 9
4 years ago
Edited 4 years ago

So basically I want a hitbox system. On "wait(0.84)," that's around where the animation grabs out, and if it finds a player near the hitbox, it'll weld them together to show a grabbing animation (thanks oil sauce :^) ) Im having two problems and I need some tips. Does anyone know to make the region scan around my torso? It needs to update the region position to my torso so it'll be able to know if anyone is in reach. Also, is there any way to make it not be able to grab the main character's humanoid instead of the victim? I tried workspace:FindPartsInRegion3(region, humanoid,1000) since I had humanoid in a local path, but that didn't seem to work. I appreciate any help, thanks!

local deb = false
local Animation = game.ReplicatedStorage.Animation


game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
    local character = player.Character
    local humanoid = character.Humanoid
    local AnimationTrack = humanoid:LoadAnimation(Animation)
    local rootPart = character:WaitForChild("HumanoidRootPart")
    local region = Region3.new(Vector3.new(0,0,0), Vector3.new(15, 15, 15))

local part = Instance.new("Part")
    --[[
    local enemyChar = 4 --Ignore this! I need the hitbox to get the player's position! Can't do that currently
    local enemyRootPart = 4 --enemyChar:WaitForChild("HumanoidRootPart")
    --]]
    if deb then return end
    deb = true
    AnimationTrack:Play()
    wait(0.84)
    local partsInRegion = workspace:FindPartsInRegion3(region, humanoid,1000)
    for i, part in pairs(partsInRegion) do
        if part.Parent:FindFirstChild("Humanoid") ~= nil then
            print("Player found in the region!: ".. part.Parent.Name)
        end
    end
    wait(2)
    deb = false
end)

Answer this question