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

Why wont this damage the humanoid on hit? [Hopperbin]

Asked by 9 years ago

Theres no error's, but when the bullet should find "Humanoid" it fails to complete.

How would I make it so the bullet gets the players character then gets the Humanoid -> Health and add damage?

P.Touched:connect(function(part) -- Fire the bullet and the bullet touchs the position..
            Box.Transparency=1
            P.Transparency=1

            local function asd()
                coroutine.resume(coroutine.create(function()
                local PA=Instance.new('Part',workspace)
                PA.Transparency=1
                local Box2=Instance.new('SelectionBox',PA)
                Box2.Adornee=PA
                Box2.Color=BrickColor.new('Teal')
                Box2.Transparency=.1
                PA.Anchored=false
                PA.CanCollide=false
                PA.Locked=true
                PA.Name = 'Bullet_Explosion'
                PA.FormFactor='Custom'
                PA.Position=Vector3.new(part.Position.X,part.Position.Y,part.Position.Z)
                PA.Size=Vector3.new(math.random(1,8.5),math.random(1,8.5),math.random(1,8.5))
                PA.Rotation=Vector3.new(math.random(1.5,275),math.random(1.5,215),math.random(1.5,200))

                Bullet = PA

                if part.ClassName == 'Humanoid' then
                    part.Health:TakeDamage(5)                                       -- PROBLEM HERE--
                end

            end 

            for i = 0,4,1 do
                asd()
            end

            wait(math.random(.1,1))
            P:remove()
            Bullet:remove()

        end)

1 answer

Log in to vote
0
Answered by 9 years ago

P.Touched:connect(function(part) -- Fire the bullet and the bullet touchs the position.. Box.Transparency=1 P.Transparency=1

        local function asd()
            coroutine.resume(coroutine.create(function()
            local PA=Instance.new('Part',workspace)
            PA.Transparency=1
            local Box2=Instance.new('SelectionBox',PA)
            Box2.Adornee=PA
            Box2.Color=BrickColor.new('Teal')
            Box2.Transparency=.1
            PA.Anchored=false
            PA.CanCollide=false
            PA.Locked=true
            PA.Name = 'Bullet_Explosion'
            PA.FormFactor='Custom'
            PA.Position=Vector3.new(part.Position.X,part.Position.Y,part.Position.Z)
            PA.Size=Vector3.new(math.random(1,8.5),math.random(1,8.5),math.random(1,8.5))
            PA.Rotation=Vector3.new(math.random(1.5,275),math.random(1.5,215),math.random(1.5,200))

            Bullet = PA
    human = part.Parent:FindFirstChild:("Humanoid")
            if human ~= nil then
                part.Health:TakeDamage(5) --This might work, also try "part.Health = part.Health - 5"
    --If this doesnt work, try moving where it finds the human somewhere else...hope this works                                 or at least helps :D
            end

        end 

        for i = 0,4,1 do
            asd()
        end

        wait(math.random(.1,1))
        P:remove()
        Bullet:remove()

    end)
Ad

Answer this question