part.Touched not firing

I am trying to make a script which functions similar to buttons in Flood Escape 2; once pressed, a certain feature of a level is revealed allowing for the players to advance. This is my current script:

local Pressed = script.Parent.Pressed
local Unpressed = script.Parent.Unpressed
local Activated = script.Parent.Parent.Activated
local Reverse = script.Parent.Parent.Reverse

if Reverse.Value == false then
	for _, child in ipairs(Activated:GetChildren()) do
		child.Transparency = .5
		child.CanCollide = false
	end
else
	for _, child in ipairs(Activated:GetChildren()) do
		child.Transparency = 0
		child.CanCollide = true
	end
end

Pressed.Touched:Connect(function()
	if Pressed:FindFirstChildWhichIsA("Humanoid") then
		Pressed.Transparency = 1

		Unpressed.Transparency = 1

		if Reverse.Value == false then
			for _, child in ipairs(Activated:GetChildren()) do
				child.Transparency = 0
			end
		else
			for _, child in ipairs(Activated:GetChildren()) do
				child.Transparency = 1
			end
		end
	end
end)

And this is the hierarchy in which the script is:
image

The script, however fails to fire at line 18:

 Pressed.Touched:Connect(function()

I have tried putting a break point for the first line within that code block, which does not fire, as well as at the beginning to see where the script could be bugging out, however the script runs through the “if Reverse.Value == false then” code block flawlessly, and reaches the end.

What can I do to make the “Pressed” block of the script work?

1 Like

Try It

local Pressed = script.Parent.Pressed
local Unpressed = script.Parent.Unpressed
local Activated = script.Parent.Parent.Activated
local Reverse = script.Parent.Parent.Reverse

if Reverse.Value == false then
	for _, child in ipairs(Activated:GetChildren()) do
		child.Transparency = .5
		child.CanCollide = false
	end
else
	for _, child in ipairs(Activated:GetChildren()) do
		child.Transparency = 0
		child.CanCollide = true
	end
end

Pressed.Touched:Connect(function(Part)
	if Part.Parent:FindFirstChildWhichIsA("Humanoid") then
		Pressed.Transparency = 1

		Unpressed.Transparency = 1

		if Reverse.Value == false then
			for _, child in ipairs(Activated:GetChildren()) do
				child.Transparency = 0
			end
		else
			for _, child in ipairs(Activated:GetChildren()) do
				child.Transparency = 1
			end
		end
	end
end)

You have to use the touched function variable to get to the part and check if this part is part of a humanoid, there you check the part where you step.

3 Likes

Pressed.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then

1 Like

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