I have a script that detects parts in a region3, and I get the parent of a part (the player model) and put them in a table. But, on the removal script, I check if the player is in the region3 part's table, but it's a table with the parts, not the player model. So I wanted to know if there is a way of getting the part's parent when getting the parts in the region3. This is my script:
local RaceFolder = script.Parent.Parent
local RaceLocation = RaceFolder.Parts.RaceLocation
local region3 = Region3.new(RaceLocation.Position-(RaceLocation.Size/2),
RaceLocation.Position+(RaceLocation.Size/2)
)
local function findIndex(table,value)
for i,v in pairs(table) do
if v == value then
return i
end
end
end
local tableRacers = {}
local tableInRaceLocation = {}
local function PlayersInRaceLocation(player)
local whitelist = game.Workspace:WaitForChild(player.Name):GetChildren()
local InRegion = game.Workspace:FindPartsInRegion3WithWhiteList(region3,whitelist,math.huge)
for i,v in pairs(InRegion) do
print(v)
if v.Parent.Name == player.Name then
if not table.find(tableInRaceLocation,player) and table.find(tableRacers,player) then
print("Added")
table.insert(tableInRaceLocation,#tableInRaceLocation+1,player)
end
end
end
for i,v in pairs(tableInRaceLocation) do
if not table.find(InRegion,v) and table.find(tableRacers,v) then
table.remove(tableInRaceLocation,findIndex(tableInRaceLocation,v))
print("Removed!")
end
end
end
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = folder
while true do
wait()
PlayersInRaceLocation(player)
end
end)

3 comments
Loop through all items in region3 and get their parent
Ok lemme try that.
That didn't work.