Am i using :GetTouchingParts() wrong?

idk what a world root yet so this is best variant

function test ()
	for i, v in pairs(crystal.zone:GetTouchingParts()) do
		if v == hrp then
			print("IT WORKS")
        end

		if  v == redcrystal then
			print("RED CRYSTAL WORKS TOO")
		else
			print("IT DOESNT WORK")
		end
	end
end

no… variable name doesnt change anything

I was having the same issue about two days ago, this is what I did that worked for me:

local Area = script.Parent:WaitForChild("Area")
local PartsInArea = workspace:GetPartBoundsInBox(Area.CFrame, Area.Size, OverlapParams.new())

for i = 1, #PartsInArea do
	if PartsInArea[i].Name == "PartName" then
		print("PartFound")
	end
end

I have this within a function and it works flawlessly for me.

Edited had to fix a line of this script, should work now.

I used the code from a youtube video and it works now. only downside is i have to cover the zone with 6 faces between some space to revert the values.

script.Parent.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		if player.Stats.FS.Value >= script.Parent.Parent.Req.Value then
		   player.Backpack.FSZoneMulti.Value = 1000
		end
	end
end)

fixed version of GetPartsInPart probably best one

function test ()
	for i, v in pairs(workspace:GetPartsInPart(crystal.Zone)) do
		if v == hrp then
			print("IT WORKS")
		elseif  v == redcrystal then
			print("RED CRYSTAL WORKS TOO")
		else
			print("IT DOESNT WORK, or its another part")
		end
	end
end
1 Like