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

Help with gun bullet not taking away health?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago

In a LocalScript in my gun. The only problem is, when a bullet hits something with a humanoid, it does not take any damage at all. I would like for it to do so though.

Player = game.Players.LocalPlayer
Character = Player.Character
Gun = script.Parent
Mouse = Player:GetMouse()

--<< Changeable Values >>--
Gun_Speed = 2000 --The higher, the faster.
Gun_Distance = 7000 --The higher, the longer distance it goes.
TakeAway_Health = 10

Gun.Equipped:connect(function()
    Mouse.Icon = "http://www.roblox.com/asset/?id=43910485"
    local function PullTrigger()
        local Bullet = Instance.new("Part", game.Workspace)
        Bullet.CanCollide = false
        Bullet.Name = Player.Name
        Bullet.Size = Vector3.new(0.3,0.3,0.3)
        Bullet.Shape = "Ball"
        Bullet.BrickColor = BrickColor.new("White")
        Bullet.TopSurface = "Smooth"
        Bullet.BottomSurface = "Smooth"

        Bullet.Touched:connect(function(Hit) --PROBLEM IS HERE!
            if Hit.Parent:FindFirstChild("Humanoid") == nil and Hit.Parent.Name == script.Parent.Name then
                for i = 1,100 do
                    Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health - TakeAway_Health
                end
            end
        end)

        Bullet.CFrame = Gun.Handle.CFrame
        Bullet.CFrame = CFrame.new(Bullet.Position, Mouse.Hit.p)
        Bullet:BreakJoints()

        local Power = Instance.new("BodyVelocity", Bullet)
        Power.Velocity = Bullet.CFrame.lookVector * Gun_Speed --Bullet Speed
        Power.MaxForce = Vector3.new(Gun_Distance,Gun_Distance,Gun_Distance) --How long it travels
    end
    Gun.Activated:connect(PullTrigger)
end)
0
on line 24-25, are you sure you mean ==? looks like you want ~= there. pwnd64 106 — 7y
0
I agree^ User#11440 120 — 7y
0
Did not work still FiredDusk 1466 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

It should be ~= not ==

0
In line 24 UltraUnitMode 419 — 7y
0
Still did not work. FiredDusk 1466 — 7y
Ad

Answer this question