How can you make a tool that you can use in certain area?

Greeting’s! I’m having some trouble on getting some idea’s on how I could script this.
The thing is, I don’t know where to start. I’m trying to make an area that a tool can be activated in the selected area. (The player must be in the area too.) I will now show you a picture of what i mean:

  • The green area was the area i was talking about. (A block to be exact.)
  • The orange stick-figure is the Player.
  • The blue axe is the tool.

The picture below me Is the Player holding the axe, Outside of the area.(The block.)
But as you can see, the Player is holding it But not being able to activate the tool.

Picture1

Now the Player and the axe below me is now being Inside the area. It is being allowed to use (Activate.) the axe.
Picture2

I have already made the tool and area, But i do not know how to make the script that i need.
And i have been looking through the developer form, and outside of it to find nothing of use.
Anyway, I would like someone to Help me create this script by giving me some help to do so.
Thank you for you’re time.

1 Like

I actually made code that does exactly this. Region3’s are what I used. Basically, you create a new Region3 object once, then you call workspace:FindPartsInRegion3() to return a list of all BaseParts that are in the region.

I don’t entirely remember how to create a region around a given part, but I’m pretty sure it’d be pretty close to the following code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local base = workspace.BasePart --//The region will be cast around this part
local size, pos = base.Size, base.Position

local zoneMin = pos - Vector3.new(size.X/2, size.Y/2, size.Z/2) --//The two corners for our Region3 object
local zoneMax = pos + Vector3.new(size.X/2, size.Y/2, size.Z/2)

local region = Region3.new(zoneMin, zoneMax) --//Construct new Region3 object

local function Is_Player_In_Zone() --//Determine if the player is in our Region3 object
local parts = workspace:FindPartsInRegion3(region)

for _, part in pairs(parts) do
if part:IsDescendantOf(character) then
return true --//A part was found in this region that's a member of the player model
end
end

end

while wait(1) do
print(Is_Player_In_Zone())
end

Hope this helps!

2 Likes

As @C_Sharper Mentioned, workspace:FindPartsInRegion3() is a great way to detect players Leaving and Entering certain Areas.

To convert a Part into a Region3, You can use the code provided by the user XAXA to convert any given part and then link it up with workspace:FindPartsInRegion3() and your tool system.

2 Likes

Hello. Thank you for the reply’s and trying to help me but, I’m still quite confused on how i can ‘Link it up.’ with Activating my tool in the area. And also, I still have no idea on how I can set these script’s and make them work. Maybe you can explain it a bit further please if possible?
(P.s Sorry for the late reply, i’m quite shy on these platform’s.)