Am i using :GetTouchingParts() wrong?

I have this script which makes the tool increase the amount of stat it gives when activated if player is in the zone (An invisible cube i made) and has the enough stats required. I tought i could use :GetTouchingParts() but it hink i used it wrong.

if hrp:GetTouchingParts(crystal.Zone) then
	if stat >= crystal.Req.Value then
		stat = stat + (multi * crystal.Multi.Value)
		print("CRYSTAL")
		debounce = true
		wait(1)
		debounce = false
	elseif stat < crystal.Req.Value then
		stat = stat + multi
	end
end

If you check the documentation, you’ll see it doesn’t take any parameters but instead returns a list of all parts currently being touched.

for i, v in hrp:GetTouchingParts() do
    if v == crystal.Zone then
        -- do stuff
    end
end

Oh. Okay thanks for the info. BTW i will have more than 1 crystal so should it be ok if i use the same technique for all in one script or should i have a number value in backpack that would change dependinging on the crystal if has stat required?

Do the zones both do exactly the same thing? If so, just use or:

-- same as above but
    if v == crystal.Zone or v == crystal2.Zone then

If not, you can use elseif:

-- same as above but
    if v == crystal.Zone then
        -- do stuff
    elseif v == crystal2.Zone then
        -- do other stuff
    end

It’s ultimately up to you how you do it though so long as you consider it to be organized.

Okay i tried editing the script and i couldnt get it to work. It only prints the “IT DOESNT WORK” twice

function test ()
	for i, v in hrp:GetTouchingParts() do
		if v == crystal.Zone then
			print("IT WORKS")
			if v == redcrystal then
				print("RED CRYSTAL WORKS TOO")
			end
		else
			print("IT DOESNT WORK")
		end
	end
end

wait, what a crystal.Zone? do you need to get touching parts from it, or from hrp?

crystal is the group and crystal.Zone is the invisible block. Im trying to make a game like spts

so first of all you need to crystal.Zone:GetTouchingParts(), because its a invisible block.

then, what a hrp?

Ok but it has to connect with player. I made the stats like this. game.Players.Stats.(4 number values). And i have the script in the tool which gives the player one of the 4 stats. Theres a multiplier player can buy and a multiplier player can have from zones if they meet the required stat.
Hrp is humanoid root part.

Why not use GetPartsInPart()?

edited

function test ()
	for i, v in pairs(crystal.zone:GetPartsInPart()) 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

Does it let me do stuff like

If  debounce == false then
  if humanoidrootpart **TOUCH** crystal.Zone then
       stat = stat + (multi * zonemulti)
  else stat = stat + multi
   end
end

The “GetPartsInPart()”

look above --------------------

oh, sorry, mistake, do this:

function test ()
	for i, v in pairs(crystal.zone:GetPartsInPart()) 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

Im getting this error here

GetPartsInPart is not a valid member of Part "Workspace.Zones.FS.Crystal.Zone"  -  Server - Script:8

and since i dont know how to use the get parts in part i cant solve it.

also crystal.Zone needs a big Z.

then use

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

oh, i think i got it, try
for i, v in pairs(WorldRoot:GetPartsInPart(crystal.Zone)) do
if it work, its better then touching parts

im getting an error again.

Players.Ozhan02.Backpack.test tool.Script:8: attempt to index nil with 'GetPartsInPart'  -  Server - Script:8

code im using now…

function test ()
	for i, v in pairs(WorldRoot:GetPartsInPart(crystal.Zone)) 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

Its in a tool btw with a tool.Activated:Connect(test)
Requires a handle and ManualActivationRequired are off

I watched a video about doing the same thing and the guy uses a (hit) parameter where he uses :GetPlayerFromCharacter(hit.Parent) ill try that and come back