Why is my touched event not working

idk why is this happening but im using tag editor

for _, Pad in pairs(Pads) do
	Pad.Touched:Connect(function(hit)
		print("touched")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		AddPlayer(player, Pad)
	end)
end

touched doesn’t print i have it as parts

please follow the suggested format when posting, what are you trying to achieve?

im trying to achieve that the touched event should work

You need to check if the part you touched is part of a character model:

for _, Pad in pairs(Pads) do
	Pad.Touched:Connect(function(hit)
		print("touched")
        if hit.Parent:FindFirstChild("Humanoid") then
		    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		    AddPlayer(player, Pad)
        end
	end)
end

i just said the touched doesn’t print

Can you show us the pads in the explorer?

Ah, there’s your problem. Your using .touched on a folder, which a folder doesn’t even have.

im using tag editor and this is the result

1 Like

Do you get any errors in your output?

not a single error in my output

i tried printing outside the loop and it didn’t print

Is this a local script? And where is this script located?

im using aero and its a server side module

Can you provide all the code that’s related to the module? Cause just from that one code, we can’t really do much for you.

Also whats aero?

a framework and here is the full code

-- Pad Service
-- FerbZides
-- August 23, 2020

--[[
	
	Server:
		
	


	Client:
		
	

--]]



local PadService = {Client = {}}

local PathfindingService = game:GetService("PathfindingService")
local CollectionService = game:GetService("CollectionService")
local PadsPart = CollectionService:GetTagged("Pads")

-- Events
local PLAYER_LEFT = "PlayerLeft"

function PadService:Start()
	-- move them to the part and their walkspeed
	local function MovePlayers(Player, Part, Speed)
		-- Define humanoid then move them
		local character = Player.Character
		local Humanoid = character.Humanoid
		
		-- Change speed
		Humanoid.WalkSpeed = Speed
		
		local path = PathfindingService:CreatePath()
		path:ComputeAsync(character.HumanoidRootPart.Position, Part.Position)
		for _, WayPoints in pairs(path:GetWayPoints()) do
			Humanoid:MoveTo(WayPoints.Position)
			Humanoid.MoveToFinished:wait()
		end
	end
	
	-- just to check if they are a real character
	local function PlayerIsInGame(Player)
		if Player then
			if Player.Character then
				return true
			end
		end
	end
	
	-- Pad functions
	
	-- Add player
	local function AddPlayer(Player, Part)
		if PlayerIsInGame(Player) then
			
			-- Define part values
			local Taken = Part.Taken
			local PadOwner = Part.Owner
			
			-- Define its stats
			local PadData = Player:WaitForChild("PadData")
			local CourtName = PadData:WaitForChild("CourtName")
			local PadName = PadData:WaitForChild("PadName")
			local OnSpot = PadData:WaitForChild("OnSpot")
			local TeamName = PadData:WaitForChild("TeamName")
			
			-- Define the court
			local CourtFolder = Part.Parent.Parent.Parent
			local Config = CourtFolder.Configuration
			local GamePlayers = Config.GamePlayers
			local Team1Folder = GamePlayers.Team1
			local Team2Folder = GamePlayers.Team2
			
			-- Functions
			local function CheckPlayers()
				local CheckNumber = 0
				
				for _, Player in pairs(game.Players:GetPlayers()) do
					-- check then add 1
					if Team1Folder:FindFirstChild(Player.Name) then
						CheckNumber = CheckNumber + 1
					elseif Team2Folder:FindFirstChild(Player.Name) then
						CheckNumber = CheckNumber + 1
					end
				end
				
				-- returning it to whoever called it
				return CheckNumber
			end
			
			-- Checks then add
			if OnSpot.Value == false and CourtName.Value ~= CourtFolder.Name and Taken.Value == false and PadOwner.Value == "" then
				-- Move them
				Part.Decal.Color3 = Color3.fromRGB(255, 115, 0)
				MovePlayers(Player, Part, 0)
				
				-- Add value
				local Value = Instance.new("StringValue")
				Value.Name = Player.Name
				Value.Value = tonumber(Part.Name)
				
				-- set it after the check
				if Part.Parent.Name == "Team1" then
					Value.Parent = Team1Folder
				elseif Part.Parent.Name == "Team2" then
					Value.Parent = Team2Folder
				end
				-- Set stats
				CourtName.Value = CourtFolder.Name
				PadName.Value = tonumber(Part.Name)
				OnSpot.Value = true
				TeamName.Value = Part.Parent.Name
			end
		end
	end
	
	-- Remove player
	local function RemovePlayer(Player, Part)
		if PlayerIsInGame(Player) then
			
			-- Define part values
			local Taken = Part.Taken
			local PadOwner = Part.Owner
			
			-- Define its stats
			local PadData = Player:WaitForChild("PadData")
			local CourtName = PadData:WaitForChild("CourtName")
			local PadName = PadData:WaitForChild("PadName")
			local OnSpot = PadData:WaitForChild("OnSpot")
			local TeamName = PadData:WaitForChild("TeamName")
			
			-- Define the court
			local CourtFolder = Part.Parent.Parent.Parent
			local TPBack = CourtFolder.TPBack
			local Config = CourtFolder.Configuration
			local MainValues = Config.MainValues
			local GameRunning = MainValues.GameRunning
			local GamePlayers = Config.GamePlayers
			local Team1Folder = GamePlayers.Team1
			local Team2Folder = GamePlayers.Team2
			
			-- Functions
			local function CheckPlayers()
				local CheckNumber = 0
				
				for _, Player in pairs(game.Players:GetPlayers()) do
					-- check then add 1
					if Team1Folder:FindFirstChild(Player.Name) then
						CheckNumber = CheckNumber + 1
					elseif Team2Folder:FindFirstChild(Player.Name) then
						CheckNumber = CheckNumber + 1
					end
				end
				
				-- returning it to whoever called it
				return CheckNumber
			end
			
			-- check if they are on the team then destroy it
			local function RemoveValue()
				if Team1Folder:FindFirstChild(Player.Name) then
					local Obj = Team1Folder:FindFirstChild(Player.Name)
					Obj:Destroy()
				elseif Team2Folder:FindFirstChild(Player.Name) then
					local Obj = Team2Folder:FindFirstChild(Player.Name)
					Obj:Destroy()
				end
			end
			
			-- checks then remove
			if OnSpot.Value == true and GameRunning.Value == false and CourtName.Value == CourtFolder.Name and OnSpot.Value == true and PadName.Value == tonumber(Part.Name) then
				Part.Decal.Color3 = Color3.fromRGB(255,255,255)
				MovePlayers(Player, TPBack, 16)
				RemoveValue()
				-- Set stats
				CourtName.Value = "COURT_0"
				PadName.Value = 0
				OnSpot.Value = false
				TeamName.Value = "No Team"
				
			end
		end
	end
	
	for _, PadPart in pairs(PadsPart) do
		print("it ran")
		PadPart.Touched:Connect(function(hit)
			print("touched")
			if hit.Parent:FindFirstChild("Humanoid") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				AddPlayer(player, PadPart)
			end
		end)
	end
end


function PadService:Init()
	self:RegisterEvent(PLAYER_LEFT)

end


return PadService

it’s probably because you’re printing ‘touched’ (the word) instead of ‘hit’ (the person touching)

Print() will work with any string. Example;

print("hello word!")

Are you tagging the folders “Team1” and “Team2”?

1 Like

i don’t so yeah it should work but it didn’t