Touched doesnt work

the entity moving should detect that it hit door and do stuff
but it doesnt work

script.Parent.Touched:Connect(function(v)
	print(v)
	if v.Name == "door" then
		if v.Parent.Name == "new" then
			for i,v in pairs(v.Parent:GetChildren()) do
				if v.Name == "Locker1" or "Locker2" then
					script.Parent.Parent.Script:Destroy()
					local t = TweenInfo.new(
						0.25,
						Enum.EasingStyle.Quad,
						Enum.EasingDirection.In
					)
					local tween = game:GetService("TweenService")
					local function twennc(part,info,prop)
						local success,warn = pcall(function()
							tween:Create(part,info,prop):Play()
						end)
					end
					twennc(script.Parent, t, {CFrame = v.f.CFrame})
					twennc(v.door, t, {CFrame = v.doorto.CFrame})
					game.Players:FindFirstChild(v.plr.Value).Character.Humanoid.Health = 0
					wait(0.25)
					twennc(v.door, t, {CFrame = v.doorog.CFrame})
				end
			end
		end
	end
end)
1 Like

Ah, ahem, uhhh, erm hrm, eh, yes, I think I see the problem.

EDIT
Alright to give an actual solution, change the line to the following:

if ({ ["Locker1"] = true; ["Locker2"] = true; })[v.Name] ~= nil then

This should fix the issue :+1:

2 Likes

OHHH IM DUMB I DID JUST “LOCKER2” NOT V.NAME == “LOCKER2” thanks
jst im not home and monitor is so small i cant properly see logs and stuff

1 Like

hm still doesnt work idk why it doesnt print what i need and doesnt stop moving

The variable name in the loop is the same as in the touched event, it can cause problems, and where is the script located? And what doesn’t it print? v?

1 Like

yes and its child of part the monster should move
EDIT:
i changed v to e still doesnt work

This event only fires as a result of physical movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be Anchored at the time of the collision.

— BasePart documentation on the .Touched event.

1 Like

how i should move it then if it should be unanchored

Did it do the print? That would be the 1st step here. What are you seeing. Need more than “that didn’t work”…

1 Like

no it doesnt print idk why just doesnt

Well than nothing else matters if we can’t get past that…
Is this a client script? with a server script already doing things to this object?
Is touch even set up on the part? Is the part covered?

Make a part right next to it with a simple touch script that just prints ("x’)
as a test.

the script is server and the part it is in is moving it is covered by hitboxes with obvius reason can touch on

You should switch to try and use Instance:GetPartBoundsInBox(). Then check if the entity is touching any part which in this is Hitbox? and if it is then do the same logic you have here.
I assume this would work better because as said below which was said above lol

This event only fires as a result of physical movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be Anchored at the time of the collision.

— BasePart documentation on the .Touched event.

This article below links you to the Documentation which states
"WorldRoot:GetPartBoundsInBox() returns an array of parts whose bounding boxes overlap a box whose volume is described using the given center (CFrame) and size (Vector3). "

This means that it is based on the given CFRAME and not what .Touched uses.

This shouldn’t be that hard… it’s just a touch. There is something else out of place or not set up right.

Yes, for a normal Touched event it shouldn’t but Touched only works on Physical movement. Example if you anchor your Character and the descendants in workspace and put a kill brick it should not in theory kill you because you’re anchored and not putting out any physical movement.

Then I’m sure this is not a problem of the script, but the parts themselves. For some reason the part doesn’t detect touches. Can you share us their properties?

Do you have CanTouch unticked for both instances? Maybe that’s why.

i have cantouch enabled everywhere, sorry for delay