The goal of this script is to constantly output a value when the player is inside and outside the range. When there is a player, it assigns a value 1, and an object moves.
The problem arises when I am trying to move a region3 to a new area while the RegionPart moves: the region3 is not updated and the position from my first value stays the same. Therefore as the object moves, my region3 does not.
local PayloadSystemValue = game.ReplicatedStorage.PayloadValue
local RS = game:GetService("RunService")
local RegionPart = game.Workspace:WaitForChild("Region")
local function regionSystem(regionPos)
-- gets the region3 using a part
local pos1 = regionPos - (RegionPart.Size/2)
local pos2 = regionPos + (RegionPart.Size/2)
local plrCount = 0
local partsInRegion = workspace:FindPartsInRegion3(Region3.new(pos1,pos2), nil, 1000)
-- checks if there is atleast one person
for _, part in pairs(partsInRegion) do
if part.Parent:FindFirstChild("Humanoid") then
plrCount = 1
end
end
PayloadSystemValue.Value = plrCount
return
end
RS.Stepped:connect(function()
regionSystem(RegionPart.Position)
print(game.Workspace.Tesobj.Position)
end)