It's still kill me even outside

So basically…

I have a part script that kills you while you’re holding or equipping a harmed tools such as guns or whtever whenever in Church

But I don’t know why it kills me while equipping a weapon even outside while I didn’t touch the part.

The script looks like this

local Blacklisted_Tools = {
	"MAD DEAGLE",
	"california",
	"9mm",
	"M16",
	"Uzi",
	"london"
}

local Death = game.ReplicatedStorage:WaitForChild("Death_Reason")
local Text = "NO HARM TOOLS ARE ALLOWED IN CHURCH!"

script.Parent.Touched:Connect(function(BasePart)
	local Guy = BasePart.Parent:FindFirstChild("Humanoid")
	if Guy and Guy.Parent:IsA("Model") then
		local Char = Guy.Parent
		local Tools = Char:FindFirstChildWhichIsA("Tool")
		for i = 1,#Blacklisted_Tools do
			if Tools and string.upper(Tools.Name) == string.upper(Blacklisted_Tools[i]) then
				Guy.Health = 0
				if not BasePart.Parent.Head:FindFirstChild("Death_Reason") then
					local DClone = Death:Clone()
					DClone.Parent = BasePart.Parent:FindFirstChild("Head")
					DClone.TextLabel.Text = Text
				end
			else
				Char.ChildAdded:Connect(function(child)
					for i = 1,#Blacklisted_Tools  do
						if string.upper(child.Name) == string.upper(Blacklisted_Tools[i]) then
							Guy.Health = 0
							if not BasePart.Parent.Head:FindFirstChild("Death_Reason") then
								local DClone = Death:Clone()
								DClone.Parent = BasePart.Parent:FindFirstChild("Head")
								DClone.TextLabel.Text = Text
							end
						end
					end
				end)
			end
		end	
	end
end)

Any help is appreciated…

11 Likes

Because, when you leave the part, the Char.ChildAdded still runs
so replace Char.ChildAdded:Connect to Char.ChildAdded:Once

1 Like

this becomes

Char.ChildAdded:Once(function(child)
1 Like

You should create a debounce that is false when the TouchEnded fires
and true when Touched fires

So that variable shows if ur inside or not.

put an if debounce then to the script where it would kill you.

so it will only kill yu when debounce = true (so when ur inside)

1 Like

I’m going to argue that .TouchEnded is not that reliable

3 Likes

Well :Once() isnt the solution here lol

Once fires ONCE in a section, so the thing you made doesnt change anything, it makes the player fire the event only once after he enters the church. Once doesnt check if ur inside or not

2 Likes

the inital problem is that when the player leaves,

Char.ChildAdded would still listen

so I guess:

local connection
local Blacklisted_Tools = {
	"MAD DEAGLE",
	"california",
	"9mm",
	"M16",
	"Uzi",
	"london"
}

local Death = game.ReplicatedStorage:WaitForChild("Death_Reason")
local Text = "NO HARM TOOLS ARE ALLOWED IN CHURCH!"

function childAdded(child)
	for i = 1,#Blacklisted_Tools  do
		if string.upper(child.Name) == string.upper(Blacklisted_Tools[i]) then
			child.Parent.Humanoid.Health = 0
			if not child.Parent.Head:FindFirstChild("Death_Reason") then
				local DClone = Death:Clone()
				DClone.Parent = child.Parent:FindFirstChild("Head")
				DClone.TextLabel.Text = Text
			end
		end
	end
    connection:Disconnect()
    connection = child.Parent.ChildAdded:Connect(childAdded)
end

script.Parent.Touched:Connect(function(BasePart)
	local Guy = BasePart.Parent:FindFirstChild("Humanoid")
	if Guy and Guy.Parent:IsA("Model") then
		local Char = Guy.Parent
		local Tools = Char:FindFirstChildWhichIsA("Tool")
		for i = 1,#Blacklisted_Tools do
			if Tools and string.upper(Tools.Name) == string.upper(Blacklisted_Tools[i]) then
				Guy.Health = 0
				if not BasePart.Parent.Head:FindFirstChild("Death_Reason") then
					local DClone = Death:Clone()
					DClone.Parent = BasePart.Parent:FindFirstChild("Head")
					DClone.TextLabel.Text = Text
				end
			else
		       	connection = Char.ChildAdded:Connect(childAdded)
			end
		end	
	end
end)
2 Likes

The “connection” and “Once:” still didn’t work.

any errors?

gufjftjufyjyfjhfjfyjyfj

Wait nevemind I found the solution. I removed the “else” and everything went fine. Yeah I’m really dumb…

2 Likes

Anyways I’m sorry for take your time and I solved it by myself. Thank you very much

2 Likes

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