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

Why aren't players taking damage from the Hitbox even when it spawns on them?

Asked by 3 years ago
Rep.Events.Combat.OnServerEvent:Connect(function(Player, Action)
    if Action == "Light" then
        local hit = false
        local Character = Player.Character or Player.CharacterAdded:Wait()
        local Hitbox = game:GetService("ServerStorage").Hitbox:Clone()
        Hitbox.Parent = workspace
        local offset = Vector3.new(0,0,-2)
        Hitbox.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(offset)

        wait(.15)
        Hitbox.Parent = nil
        Hitbox.Touched:Connect(function(Touched)
            if not hit and not Touched:IsDescendantOf(Player.Character) and Touched.Parent:FindFirstChild("HumanoidRootPart") then
                hit = true
                Touched.Parent:FindFirstChild("Humanoid"):TakeDamage(10)        
                    FX.Parent = workspace
                    FX.CFrame = Touched.Parent.HumanoidRootPart.CFrame*CFrame.new(math.random(-10,5)/15,math.random(-10,5)/15,math.random(-10,5)/15)
            end
        end)
        wait(.2)
        FX.Parent = nil
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You are using the touched function which only works when the player actually moves around. To fix this you can instead make the hitbox continously search for players inside of it and deal damage to them refer to this for more help https://devforum.roblox.com/t/how-do-you-check-if-the-player-is-in-certain-area/121163/11

Ad

Answer this question