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

Script not killing person on opposite team on Touched?

I want the door to be able to kill a person who is not on the team for ex: Blue and if a person tries to enter whenever it's closed they die..

What am I doing wrong?...

val = script.Parent.Parent.Parent.Value -- Open / Closed Value

function touc(part)
	local plr = script.Parent.Parent.Parent.Parent.Parent.TeamColor.Value
	--local plr = game.Players:FindFirstChild(part.Parent.Name)
	if plr then
		local h = part.Parent:FindFirstChild("Humanoid")
		if h then
			if val.Value == true then
				if part.Parent.TeamColor.Value ~= script.Parent.Parent.Parent.Parent.Parent.TeamColor.Value then
				h.Health = 0
				end
			end
		end
	end
end
script.Parent.Touched:connect(touc)

1 answer

First of all, I would not use a .Touched but instead use a .Hit. For some reason I have problems if I used .Touched instead of .Hit.

I am not sure where to lead this to, but I'll just remake your entire script just because I have the time and effort to do it.

Try this:

val = script.Parent.Parent.Parent.Value

script.Parent.Hit:connect(function(part)
	local ptc = script.Parent.Parent.Parent.Parent.Parent.TeamColor.Value;
	local fp = part:FindFirstChild("Humanoid");

	if fp == true then
		if val == true then
			if part.TeamColor.Value ~= ptc then
				fp.Health = nil;
			end
		end
	end
end)

Contact me if there's anything wrong.

5 comments

0

.Hit isn't an event :c

0

I actually have used it many times before, try lower casing it. If it doesn't work at all then blame Roblox updates.

0

I have tried it. That's how I know it doesn't work.

0

You can try replacing the .Hit even with .Touched. I realized the door you are talking about isn't a moving object meaning it can

0

*meaning it can't use the .Hit event. I still suggest you using the .Touched event.

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