hellooooo I’m following a scripting tutorial and I’m trying to make a region somewhere else in the game but I’m having trouble doing so. Here is the script and tell me if there’s something wrong.
local region = Region3.new(Vector3.new(98.874, 7.5, 213.481), Vector3.new(98.874, 7.5, 213.481))
local part = Instance.new(“Part”)
part.Position = Vector3.new(98.874, 7.5, 213.481)
part.Anchored = true
part.Size = Vector3.new(15,15,15)
part.Parent = game.Workspace
part.CanCollide = false
part.Transparency = 0.9
while true do
wait()
local partsInRegion = workspace:FindPartsInRegion3(region, part, 1000)
for i, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild(“Humanoid”) ~= nil then
print("player found in the region!: "…part.Parent.Name)
print(part.Parent.Name)
local char = part.Parent
end
end
end
1 Like
I’m not sure if this was devforum formatting messing up your code, but you have weird characters in your code.
You’re using the wrong quotes. “
as apposed to "
. You also have a an ellipsis (…
) instead of just two period characters: ..
Also you defined a Region3 with size 0
. When you construct a Region3
via Region3.new(a, b)
vector a
represents the bottom back left corner of the region, and b
representing the top forward corner. If a
and b
are the same value then the difference between the x
, y
, and z
coordinate will be 0
so your box will have no width, height, or depth.
Maybe you want to do this:
local players = game:GetService("Players")
local workspace = game:GetService("Workspace")
local box = Instance.new("Part")
box.Position = Vector3.new(98.874, 7.5, 213.481)
box.Anchored = true
box.Size = Vector3.new(15,15,15)
box.CanCollide = false
box.Transparency = 0.9
box.Parent = workspace
local region = Region3.new(box.Position - box.Size / 2, box.Position + box.Size / 2)
while true do
task.wait()
local partsInRegion = workspace:FindPartsInRegion3(region, box, 1000)
local found = {}
for i, part in pairs(partsInRegion) do
local player = players:GetPlayerFromCharacter(part.Parent)
if player and not table.find(found, player) then
table.insert(found, player)
print("player found in the region!: " .. player.Name)
end
end
end
Great it works now!! I just have a few questions so I understand what I am seeing, why did you subtract the box position by the box size divide by two and the other stuff? Is task.wait() the same as the wait function and what is local found? And the last question is what is table.find and table.insert?
The first argument passes in the bottom left corner position while the second enters the top right corner
position. The calculation basically just gets the position of the vertices required in order to create a region3.
This thread might answer your question as it contains all the necessary information about the task library - Task Library - Now Available! - Updates / Announcements - DevForum | Roblox
Found is the table in which the “Instances found in that region are stored” .
table (roblox.com)
This class contains all the methods to be used by tables.