Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

3 comments

0

How would I do that?

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.