I have a pretty simple player teleportation system - after countdown ends, players that are inside the Region3 will be teleported.
However I encountered a very strange problem - after teleportation, Region3 stops detecting those players.
Another strange thing is that this happens only when I playtest the game through Roblox, not Studio.
Code (not full):
local SS = game:GetService("ServerStorage")
...
local bindfuncs = SS:WaitForChild("BindFuncs")
local getPlayersAmount = bindfuncs:WaitForChild("GetPlayersAmount")
...
local lobbyTpZone:BasePart = lobbyFolder:FindFirstChild("TpPart", true) --part that represents the Region3
local tpRegion = Region3.new(
Vector3.new(lobbyTpZone.Position.X-(lobbyTpZone.Size.X/2), lobbyTpZone.Position.Y-(lobbyTpZone.Size.Y/2), lobbyTpZone.Position.Z-(lobbyTpZone.Size.Z/2)),
Vector3.new(lobbyTpZone.Position.X+(lobbyTpZone.Size.X/2), lobbyTpZone.Position.Y+(lobbyTpZone.Size.Y/2), lobbyTpZone.Position.Z+(lobbyTpZone.Size.Z/2))
)
...
getPlayersInZone.OnInvoke = function()
local partsInRegion = workspace:FindPartsInRegion3(tpRegion, lobbyFolder, 10000) --lobbyFolder is an instance of lobby, so the lobby itself won't be detected
return #partsInRegion
end
For the first time, when I :Invoke() function, everything works just fine.
However, after the round, when I :Invoke() bindable function again, it returns 0.
I tried re-creating Region3 again, but it didn’t work.
I don’t have much time left to finish my project - so please help.
Not sure, but :FindPartsInRegion3 is deprecated. I’d try using :GetPartBoundsInBox() instead. Instead of having to make a Region3, just use it on the part directly.
Kind of found solution for that now. Although I think it is pretty bad.
getPlayersInZone.OnInvoke = function()
local partsInRegion = workspace:GetPartBoundsInBox(lobbyTpZone.CFrame, lobbyTpZone.Size)
local returning = {}
for i, v in ipairs(partsInRegion) do
local found = false
for o, b in ipairs(lobbyFolder:GetDescendants()) do
if v == b then
found = true
break
end
end
if not found then
table.insert(returning, v)
end
end
return table.getn(returning)
end