Im trying my hand at creating doors, and ive started to make an automatic sliding door. However the problem is the whole code i have worked out in my head only works if this line of code works.
while true do local TouchingParts = script.Parent:GetTouchingParts() print(TouchingParts) wait(.5) end
And for whatever reason it does not. All I get are empty tables in the output and all im trying to do is find out whats touching the part. Im sure there is a more efficient way to do this with region3's or something, but for now I just want to see if I can get it to work, il optimize it a bit better later.
The best way is Region3 as you said.
Your method does not work because the region part your script is inside of is not collideable so :GetTouchingParts will return empty table. You could create .Touched event to create the touch interest but that's disgusting.
Regions in Roblox are quite simple, you just specify 2 vectors, TopLeft and BottomRight positions of the region. For comfort you can make the region have same size and position as specified part which will make it easier to use.
local Part = script.Parent while true do local Region = Region3.new( Part.Position - (0.5 * Part.Size), Part.Position + (0.5 * Part.Size) ) local TouchingParts = workspace:FindPartsInRegion3(Region, Part, math.huge) print(TouchingParts) wait(0.5) end
The region was created from position and half size of the part? I don't know that math is too complicated for me however it works, just remember that.
:FindPartsInRegion3 is function of workspace which returns table of all parts inside of given region, 2 argument is filter, in this case it will filter Part and all of it's descendants so they won't appear in the table, it can be nil but it's up to you, the third argument is max amount of parts you want to be in the region, i used the hugest number possible but it's up to you again.
Try adding a part that the player will touch to activate the door and add a script to that and put this:
function onTouch() --Your Script end script.Parent.onTouched:connect(onTouch)
This should work :3
Try using a proximity part that when the player hits it fire's something. If this isn't what you would like then you could comment, but I took it that you wanted an automatically opening door.
this is what I found worked for me
local Touched = false
You could remove the print
local Touched = false
while wait(.5) do -- your time here
local ProxPart = script.Parent.ProxPart -- Make a proximityPart and have the name here
ProxPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and Touched == false then -- checks if hit is a player object
Touched = true
print("Prox Touched")
-- your code here
wait(3)
Touched = false -- makes it so the player can't glitch the door
end
end)
end