I have no clue how Region3 works, but I know it is what I need.
At the moment, there is a system for a game I am developing that I would like to set up. The concept of this system is that a user places another user, themselves or an item into the input slot. The item then comes out in the output slot, altered or the same.
At the moment, I have two “regions” set up that determine the input and output, red and green.
My main problem/question is how am I able to detect parts when they are “inside the blocks”?
I’ve used Touched, and it is a very ugly method for handling this kind of system
I’ve used Region3, but the method I have is awful and doesn’t support rotated blocks
Ideally I’d like to learn a bit about Region3 on top of getting a solution for this. I’ve tried everything I possibly can to no avail.
No. I don’t want to use touched because I have to drop tools in there via CFrame and Touched won’t capture them unless I make their CFrame touch the brick first before being properly placed. The purpose of this is to capture all the bricks that are within either region and act upon them from there.
In your particular case, I would highly recommend instead raycasting from the HumanoidRootPart downwards.
Using any Region3 functions will only get you a list of potentially meaningless parts. Instead of looking for the character, have the character look for the part.
Instead of having blocks, turn them into pads that people can walk on. Afterwords, in a local script inside StarterCharacterScript, you can do the following:
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character
local torso = char:WaitForChild("Torso")
while wait(0.5) do
local hit = game.Workspace:FindPartOnRay(Ray.new(torso.Position, Vector3.new(0, -20, 0)), char)
if hit then
if hit.Name == "Pad1" then
-- communicate with the server to see if the player is actually on the pad
-- proceed to carry all following responsibilities to the server script
end
end
end
That doesn’t solve my problem though. I’m not only aiming to capture humanoids, I have to capture parts as well, so said capturing of “meaningless parts” is important and raycasting hundreds of objects downwards is going to be extremely expensive.
local Players = game:GetService("Players")
local region3 = require(game:GetService("ServerScriptService"):FindFirstChild("RotatedRegion3")) -- wherever you put the module...
local maxParts = 20
local ignore = {}
local inputPart = workspace.Part -- the part you want your region on
while wait(.5) do
local inputRegion = region3.fromPart(inputPart) -- creates a region based on your part's size and location
local insideInput = inputRegion:cast(ignore, maxParts) -- gets a list of parts in your region
for _, v in pairs(insideInput) do
if Players:GetPlayerFromCharacter(v.Parent) then
-- it's a player
else
-- it's a part
end
end
end
@EchoReaper Wait a moment, how did dragging work its way here?
@B_rcode I’m not looking to loop, just need it to run whenever a button is clicked, but I can take the code apart and work from what you’ve given me. Thanks for that (and thanks to @RyanSch02 for linking the items first, just didn’t experiment with them).
How are items getting into the input? I imagine player’s aren’t hopping around on unanchored items hoping they fling into the input. Is there some sort of dragging system for items which allows them to move items into the input?
Why do you need to check position then? Instead of spawning the tool in the input and waiting for a Touched event or Region3 to find it’s there, why can’t you just tell the script that’s currently checking that an item has been added from the code that spawns the tool?
Because I also need to ensure that it checks for players that put themselves in there. If a player goes in but not a tool, it has to check that there’s a player there. If a tool is dropped in, it has to check that a tool is there. If both are in there, it has to check for both.
Hence the title of this topic, the first sentence of the OP and the second bullet of my list of problems. I specifically put those there so that I could get an answer that wasn’t a link to a Wiki page. I’ve already checked the Wiki and it doesn’t do me well to understand how to work regions.
Going to mark a previous post as the solution so the confusion dispatches. Thanks for the help though, I do appreciate it.