I am new to Region3 and I watched some videos of it and got some reference but I do not know how to achieve what I want with it.
I am currently trying to make a model unanchor all its parts in it when it touches a specific part named “InnerExplosion”
local part = script.Parent
local region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)
while true do
local parts = workspace:FindPartsInRegion3(region, part)
for i, part in pairs(parts) do
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
print(player.Name)
end
end
end
You shouldn’t use Region3
since it’s deprecated. Instead, you can use GetPartBoundsInBox which might be easier to implement and isn’t deprecated.
GetPartBoundsInBox
returns an array of parts that overlap with the bound you specified, you simply check every frame if this box is overlapping, you can do it this way:
local RunService = game:GetService("RunService")
local Part = (PART)
RunService.Heartbeat:Connect(function()
local overlapping = workspace:GetPartBoundsInBox(part.CFrame, part.Size*Vector3.new(1.25,1.25,1.25))
for _, v in pairs(overlapping) do
if v.Name == "InnerExplosion" then -- FOUND!!
for _, val in pairs(v.Parent:GetDescendants()) do
if val:IsA("BasePart") then -- ok it's a part
val.Anchored = false
end
end
end
end
end)
btw remember to disconnect the Heartbeat
event when you’re done checking, or else it might start lagging a little bit.
3 Likes
Alright it works but it also unanchors other parts and basicly the whole map
Oh, the script I gave you unanchors every single part inside the part’s parent. In the second for
loop you can replace v.Parent: GetDescendants()
by (MODEL): GetDescendants()
2 Likes
If I put this script into a building and clone the building alot of times and place them on a map.
Would it cause alot of lag?
Depends on how fast your device is. You might wanna look into Network ownership in order to avoid lag as the server will be the one that calculates the physics.
1 Like