How do I find an part with the name "SnowBall" from GetTouchingParts()

I’m am trying to achieve is to find the first part with the Name SnowBall from GetTouchingParts()
but I’m am new to lua and tables in general and help in this topic would be nice

--			
            local Touch = CloneCheckingSnowBallPart:GetTouchingParts()
			if table.find(Touch, "SnowBall") then
				print("GotSnowBall")
				HoldingSnowBall = true
				HOLDSNOWBALLSEvent:FireServer(Touch)
			else
				print(Touch)
				print("NoSnowBallFound")
				CreateSnowBallEvent:FireServer()
				HoldingSnowBall = false
			end

you need to loop through the table which GetTouchingParts() returns

local parts = part:GetTouchingParts()
for index, part in parts do
   if part.Name=="SnowBall" then
      --code
      break
   end
end

okay i have just tried it and it didn’t work, this is how i did it

			local Touch = CloneCheckingSnowBallPart:GetTouchingParts()
			for index, Parts in Touch do
				if Parts.Name == "SnowBall" then
					print("GotSnowBall")
					HoldingSnowBall = true
					HOLDSNOWBALLSEvent:FireServer(Parts)
					break
				end
             end

You’re missing an end for the for loop there

forget to added it in the thing

Try doing print(Touch) before the if statement.

1 Like

Thanks everyone for helping me

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