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

Trying to make a region3 hitbox that doesn't hit the user too?

Asked by
hoth7 45
4 years ago

So I'm currently making a game where you pick up orbs, which give you power (a leaderstat value) and a punching system. The only problem is the punching system does region3, making it so when I hit something, I'm in the region 3 radius, so it hits me! Is there any way I can fix this? Please help someone!

Script:

Enabled = true
Combo = 1
Action = "Combat"

script.Parent.OnServerEvent:Connect(function(Player, Action, m,Power, V1)
    Enabled = true
    local dmg = 10 + Power * 1
    print("Got this far.")
    if Enabled == false then return end
    print("Got this far. 2")
    if Action  == Action then
        print("Got this far. 3")
        if Combo == 1 then
            print("Got this far. 4")
            Combo = 2
            print("Got this far. 5")
            local Track = Instance.new("Animation")
            Track.AnimationId = "rbxassetid://6024898273"
            Track.Name = "Anim"
            local Anim = Player.Character.Humanoid:LoadAnimation(Track)
            Anim:Play()
        elseif Combo == 2 then
            Combo = 1
            local Track = Instance.new("Animation")
            Track.AnimationId = "rbxassetid://6025098835"
            Track.Name = "Anim"
            local Anim = Player.Character.Humanoid:LoadAnimation(Track)
            Anim:Play()
        end
        wait(0.2)
        local Region = Region3.new(Player.Character.HumanoidRootPart.Position-Vector3.new(2,2,2),Player.Character.HumanoidRootPart.Position+Vector3.new(2,2,2))
        print("Got this far. 6")
        local RTable = workspace:FindPartsInRegion3(Region, nil, 20)
        print("Got this far. 7")
        for i,v in pairs(RTable) do
            print("Got this far. 8")
            local Deb = Instance.new("BoolValue", v.Parent)Deb.Name = "Deb"
            if v.Parent:findFirstChild("Humanoid") and v.Parent:findFirstChild(Deb) == nil and v.Parent ~= Player.Character then

                    print("Got this far. 9")
                print("Got this far. 10")
                game.Debris:AddItem(Deb,0.2)
                print("Got this far. 11")
                v.Parent.Humanoid:TakeDamage(dmg)
                print("Got this far. 12")
                print("Did ".. dmg .. " damage.")
                Enabled = false
            end
        end
    end
end)

I'm having trouble on line 38. Line 38 makes it so it doesn;t hit me, but doesn't hit ANYTHING else either.

Local script (not important but for extra detail):

Player = game.Players.LocalPlayer
repeat wait() until Player.Character
Character = Player.Character
mouse = Player:GetMouse()
Tool = script.Parent
multiplier = 1

Enabled = true

Tool.Activated:Connect(function()
    if Enabled == true then
        script.Function:FireServer("Combat", multiplier, Player.leaderstats.Power.Value, Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2).Position)
    end

end)

No error in the output, I was just wondering, thanks!

0
Does Player.Character actually refer to the character? Try to do: if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild(Deb) == nil and v.Parent ~= game.Workspace[Player.Name] then Hydrogyn 155 — 4y

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

on line 38 as you've stated, its not working. the reason why its not working is your looking for a created "tag" and inserting it into everything that your region3 finds

Code:

-- code
  --[[ Here -->>]]    local Deb = Instance.new("BoolValue", v.Parent)Deb.Name = "Deb"
            if v.Parent:findFirstChild("Humanoid") 
        and v.Parent:findFirstChild(Deb) == nil  -- this wont work as FindFirstChildNeeds a string/name!
        and v.Parent ~= Player.Character then
-- more code

I tested your code whilst commenting out that part and your debis call also and it seems to work as intended

Code in full:

Enabled = true
Combo = 1
Action = "Combat"

script.Parent.OnServerEvent:Connect(function(Player, Action, m,Power, V1)
    Enabled = true
    local dmg = 10 + Power * 1
    print("Got this far.")
    if Enabled == false then return end
    print("Got this far. 2")
    if Action  == Action then
        print("Got this far. 3")
        if Combo == 1 then
            print("Got this far. 4")
            Combo = 2
            print("Got this far. 5")
            local Track = Instance.new("Animation")
            Track.AnimationId = "rbxassetid://6024898273"
            Track.Name = "Anim"
            local Anim = Player.Character.Humanoid:LoadAnimation(Track)
            Anim:Play()
        elseif Combo == 2 then
            Combo = 1
            local Track = Instance.new("Animation")
            Track.AnimationId = "rbxassetid://6025098835"
            Track.Name = "Anim"
            local Anim = Player.Character.Humanoid:LoadAnimation(Track)
            Anim:Play()
        end
        wait(0.2)
        local Region = Region3.new(Player.Character.HumanoidRootPart.Position-Vector3.new(2,2,2),Player.Character.HumanoidRootPart.Position+Vector3.new(2,2,2))
        print("Got this far. 6")
        local RTable = workspace:FindPartsInRegion3(Region, nil, 20)
        print("Got this far. 7")
        for i,v in pairs(RTable) do
            print(v.Parent)
            print("Got this far. 8")
        --    local Deb = Instance.new("BoolValue", v.Parent)Deb.Name = "Deb"
            if v.Parent:findFirstChild("Humanoid")
        --[[ and v.Parent:findFirstChild(Deb.Name) == nil  --just commented this out since its not needed]] 
        and v.Parent ~= Player.Character then

                    print("Got this far. 9")
                print("Got this far. 10")
               -- game.Debris:AddItem(Deb,0.2)
                print("Got this far. 11")
                v.Parent.Humanoid:TakeDamage(dmg)
                print("Got this far. 12")
                print("Did ".. dmg .. " damage.")
                Enabled = false
            end
        end
    end
end)

I didn't touch your local script. Im assuming that tag was only for the player casting the effect/attack?

if so i would create the tag before your for loop Hope this helps! :)

Ad

Answer this question