Help with .Touched event

I am trying to do a teleporter, but the problem is, it’s not detecting the hit.
I have used another script inside the part, but that one works.
The trigger part is the white neon part.
Video:

"print "a" Script"
script.Parent.Touched:Connect(function()
	print("a")
end)
Teleport Script
TRIGGER.Touched:Connect(function(PART_THAT_TOUCHED)
	if not PART_THAT_TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then return end
	print("help")
	local DESTINATION = SCANNER.Destination
	if not DESTINATION.Value then return end
	local PLAYER = game:GetService("Players"):GetPlayerFromCharacter(PART_THAT_TOUCHED.Parent)
	local CHARACTER = PLAYER.Character
	local HUMANOID = CHARACTER.Humanoid
	local HRP = CHARACTER.HumanoidRootPart
	local VIRT_SOUND = CHARACTER:WaitForChild("VirtSound")
	local ORIGINAL_BODY_COLORS = CHARACTER["Body Colors"]
	local FAKE_BODY_COLORS = ORIGINAL_BODY_COLORS:Clone()
	FAKE_BODY_COLORS.Parent = script
	local RANDOM_VALUE = math.random(5,15)
	if IN_USE == false then
		-- do stuff
	end
end)

Help? Please?

Your white neon part IS detecting the hit!

I guess this is the problem, you want to do
script.Parent.Touched
same as in the working script. Unless there’s some other code you didn’t post which defines what TRIGGER is

1 Like

Yeah, but why doesn’t it do in the normal script?

Well uh, here is the beggining:

local SCANNER = script.Parent
local ANIMATOR = SCANNER.Energy.Animator
local OPEN_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("OpenAnim"))
local IDLE_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("IdleAnim"))
local CLOSE_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("CloseAnim"))
local TRIGGER = SCANNER.Trigger
local SCANNING_SOUND = TRIGGER:WaitForChild("Scanning")
local DOORS_SOUND = TRIGGER:WaitForChild("Doors")
local VIRT_SOUND = TRIGGER:WaitForChild("Virt")
local ALARM_SOUND = TRIGGER:WaitForChild("Alarm")
local IN_USE = false

function TurnOnScanner()
	OPEN_ANIM:Play()
	DOORS_SOUND:Play()
	wait(OPEN_ANIM.Length)
	IDLE_ANIM:Play()
end

function TurnOffScanner()
	IDLE_ANIM:Stop()
	CLOSE_ANIM:Play()
	DOORS_SOUND:Play()
end

function ChangeHumanoidMovement(Humanoid, WalkSpeed, JumpPower)
	Humanoid.WalkSpeed = WalkSpeed
	Humanoid.JumpPower = JumpPower
end
TurnOnScanner()
TRIGGER.Touched:Connect(function(PART_THAT_TOUCHED)
--continue

And the script is parented to the model, not trigger.

That’s the problem. You have to manually script it and not just rely on free models.

But it’s not a free model, I script it, from scratch!
…?

Then, you have to script the white neon part to let it teleport players.

I did that already. --do stuff represents the functions. But the problem is, as you can see in the teleport script, “help” isn’t printing.

I might be wrong but double check that these all exist in the model too, in case the script is getting stuck waiting for them? Sorry, cant see from the video if they are there or not

They are there.
image


I have duplicated the teleporter and moved it somewhere where nothing is touching, but still not working.

I don’t think you get what I meant. You’re only just making it so that it prints “a” everytime it gets touched. You have to expand your script which is scripting the teleport code in that same script.

I don’t think I get what you meant, but here is the full script:

local SCANNER = script.Parent
local ANIMATOR = SCANNER.Energy.Animator
local OPEN_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("OpenAnim"))
local IDLE_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("IdleAnim"))
local CLOSE_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("CloseAnim"))
local TRIGGER = SCANNER.Trigger
local SCANNING_SOUND = TRIGGER:WaitForChild("Scanning")
local DOORS_SOUND = TRIGGER:WaitForChild("Doors")
local VIRT_SOUND = TRIGGER:WaitForChild("Virt")
local ALARM_SOUND = TRIGGER:WaitForChild("Alarm")
local IN_USE = false

function TurnOnScanner()
	OPEN_ANIM:Play()
	DOORS_SOUND:Play()
	wait(OPEN_ANIM.Length)
	IDLE_ANIM:Play()
end

function TurnOffScanner()
	IDLE_ANIM:Stop()
	CLOSE_ANIM:Play()
	DOORS_SOUND:Play()
end

function ChangeHumanoidMovement(Humanoid, WalkSpeed, JumpPower)
	Humanoid.WalkSpeed = WalkSpeed
	Humanoid.JumpPower = JumpPower
end
TurnOnScanner()
TRIGGER.Touched:Connect(function(PART_THAT_TOUCHED)
	if not PART_THAT_TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then return end
	print("help")
	local DESTINATION = SCANNER.Destination
	if not DESTINATION.Value then return end
	local PLAYER = game:GetService("Players"):GetPlayerFromCharacter(PART_THAT_TOUCHED.Parent)
	local CHARACTER = PLAYER.Character
	local HUMANOID = CHARACTER.Humanoid
	local HRP = CHARACTER.HumanoidRootPart
	local VIRT_SOUND = CHARACTER:WaitForChild("VirtSound")
	local ORIGINAL_BODY_COLORS = CHARACTER["Body Colors"]
	local FAKE_BODY_COLORS = ORIGINAL_BODY_COLORS:Clone()
	FAKE_BODY_COLORS.Parent = script
	local RANDOM_VALUE = math.random(5,15)
	if IN_USE == false then
		print(RANDOM_VALUE)
		if RANDOM_VALUE ~= 10 then
			PLAYER.CameraMaxZoomDistance = 0.5
			IN_USE = true
			ChangeHumanoidMovement(HUMANOID,0,0)
			CLOSE_ANIM:Play()
			IDLE_ANIM:Stop()
			DOORS_SOUND:Play()
			wait(CLOSE_ANIM.Length)
			HRP.CFrame = TRIGGER.CFrame
			HRP.Orientation = TRIGGER.Orientation
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Material = Enum.Material.Neon
				GLASS_DOOR.Transparency = 0.01
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 1
			end
			SCANNING_SOUND:Play()
			wait(SCANNING_SOUND.TimeLength)
			VIRT_SOUND:Play()
			HRP.CFrame = DESTINATION.Value.CFrame
			for ITERATION, BASEPART in pairs(CHARACTER:GetChildren()) do
				if BASEPART:IsA("BasePart") then
					if BASEPART.Name ~= "HumanoidRootPart" then
						ORIGINAL_BODY_COLORS[BASEPART.Name:gsub("%s", "") .. "Color3"] = Color3.fromRGB(13, 105, 172)
					end
				BASEPART.Material = Enum.Material.ForceField
				end
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 0
				HANDLE.Material = Enum.Material.ForceField
				HANDLE.Color = Color3.fromRGB(13, 105, 172)
			end
			PLAYER.CameraMaxZoomDistance = 25
			ChangeHumanoidMovement(HUMANOID,16,50)
			VIRT_SOUND:Play()
			wait(VIRT_SOUND.TimeLength)
			ORIGINAL_BODY_COLORS.Parent = CHARACTER
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
					HANDLE.Color = Color3.fromRGB(163, 162, 165)
			end
			for ITERATION, BASEPART in pairs(CHARACTER:GetDescendants()) do
				if BASEPART:IsA("BasePart") then
					BASEPART.Material = Enum.Material.Plastic
				end
			end
			ORIGINAL_BODY_COLORS:Destroy()
			FAKE_BODY_COLORS.Parent = CHARACTER
				wait(1)
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
			local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Material = Enum.Material.Glass
				GLASS_DOOR.Transparency = 0.35
			end
			wait(3)
			OPEN_ANIM:Play()
			DOORS_SOUND:Play()
			wait(OPEN_ANIM.Length)
			IDLE_ANIM:Play()
			IN_USE = false
		else
			PLAYER.CameraMaxZoomDistance = 0.5
			IN_USE = true
			ChangeHumanoidMovement(HUMANOID,0,0)
			CLOSE_ANIM:Play()
			IDLE_ANIM:Stop()
			DOORS_SOUND:Play()
			wait(CLOSE_ANIM.Length)
			HRP.CFrame = TRIGGER.CFrame
			HRP.Orientation = TRIGGER.Orientation
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Material = Enum.Material.Neon
				GLASS_DOOR.Transparency = 0.01
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 1
			end
			SCANNING_SOUND:Play()
			wait(SCANNING_SOUND.TimeLength)
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Color = Color3.fromRGB(255,0,0)
			end
			ALARM_SOUND:Play()
			wait(ALARM_SOUND.TimeLength + 2)
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Color = Color3.fromRGB(255, 255, 255)
				GLASS_DOOR.Material = Enum.Material.Glass
				GLASS_DOOR.Transparency = 0.35
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 0
			end
			OPEN_ANIM:Play()
			DOORS_SOUND:Play()
			PLAYER.CameraMaxZoomDistance = 25
			ChangeHumanoidMovement(HUMANOID,16,50)
			wait(OPEN_ANIM.Length)
			IDLE_ANIM:Play()
			IN_USE = false
		end
	end
end)

And the print("a") script is the one screenshotted above, with only

script.Parent.Touched:Connect(function()
   print("a")
end)

So this script is patented under that white neon part?

image
TeleportScript is the one above, print("a") is print("a").

You’re just making things harder for me to understand.

Please, how can I tell it better?

TeleportScript being a child of the teleport model
local SCANNER = script.Parent
local ANIMATOR = SCANNER.Energy.Animator
local OPEN_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("OpenAnim"))
local IDLE_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("IdleAnim"))
local CLOSE_ANIM = ANIMATOR:LoadAnimation(script:WaitForChild("CloseAnim"))
local TRIGGER = SCANNER.Trigger
local SCANNING_SOUND = TRIGGER:WaitForChild("Scanning")
local DOORS_SOUND = TRIGGER:WaitForChild("Doors")
local VIRT_SOUND = TRIGGER:WaitForChild("Virt")
local ALARM_SOUND = TRIGGER:WaitForChild("Alarm")
local IN_USE = false

function TurnOnScanner()
	OPEN_ANIM:Play()
	DOORS_SOUND:Play()
	wait(OPEN_ANIM.Length)
	IDLE_ANIM:Play()
end

function TurnOffScanner()
	IDLE_ANIM:Stop()
	CLOSE_ANIM:Play()
	DOORS_SOUND:Play()
end

function ChangeHumanoidMovement(Humanoid, WalkSpeed, JumpPower)
	Humanoid.WalkSpeed = WalkSpeed
	Humanoid.JumpPower = JumpPower
end
TurnOnScanner()
TRIGGER.Touched:Connect(function(PART_THAT_TOUCHED)
	if not PART_THAT_TOUCHED.Parent:FindFirstChildOfClass("Humanoid") then return end
	print("help")
	local DESTINATION = SCANNER.Destination
	if not DESTINATION.Value then return end
	local PLAYER = game:GetService("Players"):GetPlayerFromCharacter(PART_THAT_TOUCHED.Parent)
	local CHARACTER = PLAYER.Character
	local HUMANOID = CHARACTER.Humanoid
	local HRP = CHARACTER.HumanoidRootPart
	local VIRT_SOUND = CHARACTER:WaitForChild("VirtSound")
	local ORIGINAL_BODY_COLORS = CHARACTER["Body Colors"]
	local FAKE_BODY_COLORS = ORIGINAL_BODY_COLORS:Clone()
	FAKE_BODY_COLORS.Parent = script
	local RANDOM_VALUE = math.random(5,15)
	if IN_USE == false then
		print(RANDOM_VALUE)
		if RANDOM_VALUE ~= 10 then
			PLAYER.CameraMaxZoomDistance = 0.5
			IN_USE = true
			ChangeHumanoidMovement(HUMANOID,0,0)
			CLOSE_ANIM:Play()
			IDLE_ANIM:Stop()
			DOORS_SOUND:Play()
			wait(CLOSE_ANIM.Length)
			HRP.CFrame = TRIGGER.CFrame
			HRP.Orientation = TRIGGER.Orientation
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Material = Enum.Material.Neon
				GLASS_DOOR.Transparency = 0.01
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 1
			end
			SCANNING_SOUND:Play()
			wait(SCANNING_SOUND.TimeLength)
			VIRT_SOUND:Play()
			HRP.CFrame = DESTINATION.Value.CFrame
			for ITERATION, BASEPART in pairs(CHARACTER:GetChildren()) do
				if BASEPART:IsA("BasePart") then
					if BASEPART.Name ~= "HumanoidRootPart" then
						ORIGINAL_BODY_COLORS[BASEPART.Name:gsub("%s", "") .. "Color3"] = Color3.fromRGB(13, 105, 172)
					end
				BASEPART.Material = Enum.Material.ForceField
				end
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 0
				HANDLE.Material = Enum.Material.ForceField
				HANDLE.Color = Color3.fromRGB(13, 105, 172)
			end
			PLAYER.CameraMaxZoomDistance = 25
			ChangeHumanoidMovement(HUMANOID,16,50)
			VIRT_SOUND:Play()
			wait(VIRT_SOUND.TimeLength)
			ORIGINAL_BODY_COLORS.Parent = CHARACTER
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
					HANDLE.Color = Color3.fromRGB(163, 162, 165)
			end
			for ITERATION, BASEPART in pairs(CHARACTER:GetDescendants()) do
				if BASEPART:IsA("BasePart") then
					BASEPART.Material = Enum.Material.Plastic
				end
			end
			ORIGINAL_BODY_COLORS:Destroy()
			FAKE_BODY_COLORS.Parent = CHARACTER
				wait(1)
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
			local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Material = Enum.Material.Glass
				GLASS_DOOR.Transparency = 0.35
			end
			wait(3)
			OPEN_ANIM:Play()
			DOORS_SOUND:Play()
			wait(OPEN_ANIM.Length)
			IDLE_ANIM:Play()
			IN_USE = false
		else
			PLAYER.CameraMaxZoomDistance = 0.5
			IN_USE = true
			ChangeHumanoidMovement(HUMANOID,0,0)
			CLOSE_ANIM:Play()
			IDLE_ANIM:Stop()
			DOORS_SOUND:Play()
			wait(CLOSE_ANIM.Length)
			HRP.CFrame = TRIGGER.CFrame
			HRP.Orientation = TRIGGER.Orientation
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Material = Enum.Material.Neon
				GLASS_DOOR.Transparency = 0.01
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 1
			end
			SCANNING_SOUND:Play()
			wait(SCANNING_SOUND.TimeLength)
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Color = Color3.fromRGB(255,0,0)
			end
			ALARM_SOUND:Play()
			wait(ALARM_SOUND.TimeLength + 2)
			for ITERATION, GLASS_DOOR in pairs(SCANNER:GetChildren()) do
				local loweredName = GLASS_DOOR.Name:lower()
				if not string.match(loweredName, "right") and not string.match(loweredName, "left") then
					continue
				end
				GLASS_DOOR.Color = Color3.fromRGB(255, 255, 255)
				GLASS_DOOR.Material = Enum.Material.Glass
				GLASS_DOOR.Transparency = 0.35
			end
			for ITERATION, ACCESSORY in pairs(HUMANOID:GetAccessories()) do
				local HANDLE = ACCESSORY.Handle
				HANDLE.Transparency = 0
			end
			OPEN_ANIM:Play()
			DOORS_SOUND:Play()
			PLAYER.CameraMaxZoomDistance = 25
			ChangeHumanoidMovement(HUMANOID,16,50)
			wait(OPEN_ANIM.Length)
			IDLE_ANIM:Play()
			IN_USE = false
		end
	end
end)
The print script being a child of the trigger
script.Parent.Touched:Connect(function()

print("a")

end)

In the print script it prints, but in the other one, it doesn’t. It doesn’t detect the touched input from the teleport script.

Does this print when you touched?

Figured it out. It looks like the problem is I am a big dumb noob


What was the issue?
In the teleport code, there is this line:

if not DESTINATION.Value then return end

And for some reason I didn’t set the value of the destination. bruh


What gets me is that why “help” won’t print, since it’s above the line.


Most thanks to @ItzMeZeus_IGotHacked, but it just looks like I am not that smart.

1 Like