Disable backpack in certain zones

What I’m trying to do is disable backpack in certain zones, I know about :DisableCoreGui, but how do you do this for just one person, in a certain zone, and reenable it outside of that zone? I tried using .touched, and it worked, but only once, and not again.
Edit: I rewrote the script and now it doesn’t work at all. Is there a way to disable coreguis with a server script, and what is a good example of disabling it from local script?

im not sure how you would disable the backpack, but if you are looking for players in certain zones, you can use:

(HumanoidRootPart.Position - Radius.Position).magnitude < range

for the GetTouchingParts(), it will return a table of all parts that is touching the Instance, you can resize it to make the radius larger.

for the .magnitude, you are getting the distance between the humanoidrootpart and the Position of the radius (Position is mostly the center of a part), then comparing it to the range

Any ideas for alternatives instead of disabling backpack, such as moving the tools?

im not sure how to move tools directly, but if you want to disable the backpack, try using this on a local script

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

Ok, I got it to work, but it only works when I’m touching the edges of the brick, and not when I’m inside of it.

what are you using to detect if the player is in range?

I’m just using touched/touchended.
I’ve got no clue how to do the magnitude thing from a local script.
Edit: nvm I think I figured it out thanks.

Is this good?

local player = game.Players.LocalPlayer
while true do
	char = player.Character
	HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
	Radius = game.Workspace.Part
	range = 10
	if (HumanoidRootPart.Position - Radius.Position).magnitude < range then
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

yes but you are using a wait(1), that means it will update every second. If you want you can do something that updates whenever the character moves

If I added it so if the player moves, it updates, would that be very laggy, and how would I do that?

yes it will lag very much, but what I am saying is it updates every seconds and that is fine, I am just asking if you want it to update every time the character moves

also, the

put it outside the loop since you only need it once

Edit: put this also outside the loop

Ok, I’m gonna get off, thanks for the help.

tell me if something might go wrong