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

Need help changing damage when part is at a certain distance ?

Asked by 1 year ago

I am working on a guns script and currently attempting to make it when the bullet has reached a certain distance away from its spawn point it looses a set amount of damage here Is the whole Bullet part of the script thanks for your help :D

local function CreateBullet(mouseLookVector)
    local NewBullet = Bullet:Clone()
    local ShootAnim = myHuman:LoadAnimation(AnimationFolder:WaitForChild("Shoot"))
    NewBullet.CFrame = BulletPoint.CFrame

    local direction

    local OriginalDamage = GunInfo.Damage

    NewBullet.Configs.Damage.Value = GunInfo.Damage
    NewBullet.Configs.Headshot.Value = GunInfo.Headshot
    NewBullet.Configs.HeadshotMultiplier.Value = GunInfo.HeadshotMultiplier
    NewBullet.Configs.BulletDamageFallOff.Value = GunInfo.DamageFallOff
    NewBullet.Configs.BulletDamageFallOffDistance.Value = GunInfo.DamageFallOffDistance
    NewBullet.BulletVelocity.Velocity = direction * GunInfo.BulletSpeed
    NewBullet.Parent = workspace["Bullets and Casings"]
    ShootAnim:Play()
    BulletPoint:WaitForChild("Shoot"):Play()
    wait(GunInfo.FallOffTime)
    if NewBullet then
        if NewBullet:FindFirstChild("BulletVelocity") then
            NewBullet.BulletVelocity:Destroy()
        end
    end
    if NewBullet then
        NewBullet.Velocity = mouseLookVector * GunInfo.BulletSpeed

        local lastPos = BulletPoint.Position
        while wait(0.001) do

            print((NewBullet.Position - lastPos).Magnitude)


            if NewBullet.Position >= GunInfo.DamageFallOffDistance then
                GunInfo.Damage = GunInfo.DamageFallOff

                wait(0.6)

                GunInfo.Damage = OriginalDamage

            end
        end

    end
end


Answer this question