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

Why does this harm the person who pressed the key rather than hurting the person that is touched?

Asked by 8 years ago

Why does this hurt the player that pressed the key rather than the person getting touched. I don't want the player who pressed the key to be harmed. This script is cloned into a part that shoots. When the player presses a button the part is fired

function onDamage(Part)
    if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.Name ~= script.Parent.Name then
        script.Disabled = true
        f = Instance.new("Fire", Part)
        f.Color = Color3.new(1, 0, 0)
        for i = 1,25 do
            f.Size = f.Size +0.25
            Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -2.5
            wait(0.05)
        end
        Part.Parent.Humanoid.Sit = true
        f:remove()
        script.Parent:remove()
    end
    wait(0.025)
end

script.Parent.Touched:connect(onDamage)

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Since you only gave us a portion of the code, we aren't able to provide much help. The only guess I could think of, is that when it fires the 'bullet', it touches the owner in the process. I recommend making an if statement to make sure the 'bullet' can't hurt the owner of the bullet.

0
How would I do that? Relampago1204 73 — 8y
0
The problem is that the player that shoots the part is damaged which causes my script to disable. It shouldn't hurt the other player. Relampago1204 73 — 8y
0
@Relampago1204 Create an if statement that sees who hits the bullet. Or, you can reposition th bullet so it doesn't hit the owner Shawnyg 4330 — 8y
Ad

Answer this question