Part That Damages Other Than Owner

i want to have a part that does damage on any humanoid except the owner of the part,

i did make a part appear with script in it and value in it, so owner name is always will be in the value that in the part, the problem im having is my script is not doing damage to other humanoids right now,

local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
	local owner = script.Parent:FindFirstChildOfClass("IntValue")
	local human = hit.Parent:FindFirstChild("Humanoid")

	if human and debounce == false and not hit.Parent.Name == owner.Name then

	
		human.Health = human.Health - 10
		debounce = true
	end

end)

Also i need to do damage just once thats why i dont make the debounce false again

if i understood you correctly, there is the script

local part = script.Parent
local debounce = false

part.Touched:Connect(function(hit)
	local owner = script.Parent:FindFirstChildOfClass("StringValue") --- Set value to owner's name
	local human = hit.Parent:FindFirstChild("Humanoid")

	if human and debounce == false and hit:FindFirstAncestorWhichIsA("Model").Name ~= owner.Value then

		debounce = true
		human.Health = human.Health - 10
	end

end)

Did you mean to use an InValue for the player name?

That will only hold a number.

Also you need to get the value of owner by owner.Value not owner.Name.

3 Likes

I replaced the IntValue with a StringValue. You may not want that, but the rest of the script works now:

local part = script.Parent
local debounce = true

part.Touched:Connect(function(hit)
	local owner = script.Parent:FindFirstChildOfClass("StringValue")
	local human = hit.Parent:FindFirstChild("Humanoid")
	
	if human and debounce and hit.Parent.Name ~= owner.Value then

		print("Part Stepped On By", hit.Parent)
		
		debounce = false
		human.Health = human.Health - 10
		task.wait(1) -- however long you want to wait before pad can be touched again
		debounce = true
	end

end)
2 Likes

Well the way you check for the owner confuses me a little bit.
Is the IntValues name, the name of the owner? I would recommend to use an ObjectValue or a StringValue and use the actual value property and not the name.
Other then that you should check that the humanoid that is hit isn’t already dead (so HP 0 or below) and your script should be fine I guess.

1 Like

That script doesn’t make sense, you always set the debounce to true which basically doesn’t fullfill it’s purpose as it’s only supposed to damage once when I understood @hayaliso correctly.

1 Like

It is set to false right after it is checked for true. Then the lines execute, then it sets back to true after 1 second.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.