Hi! Today I’m making a region system, basically i need to check if a player isn’t in a region this is the localscript that checks it, is located in StarterPlayerScripts, i’m also using a server script to change the team but i don’t think that is the problem, please help me!
local detectionArea = game.Workspace:WaitForChild("Regions").Prison
local region = Region3.new(detectionArea.Position - (detectionArea.Size/2), detectionArea.Position + (detectionArea.Size/2))
local player = game.Players.LocalPlayer
local found = true
while wait(1) do
local parts = workspace:FindPartsInRegion3WithWhiteList(region, player.Character:GetDescendants())
for i, v in pairs(parts) do
print("Region detected")
if v:FindFirstAncestor(player.Name) and player.Team == game.Teams.Prisoners then
print("Player found")
found = true
else
print("Player not found")
found = false
break
end
end
if found == false then
print("Changing team")
game.ReplicatedStorage.ChangeTeam:FireServer(false, "Criminals")
found = true
end
end
At the v:FindFirstAncestor
if in the not else statement i change found = true with found = false it does what it has to do; it basically doesn’t enter in the else statement.
This is the script which change the team:
local function changeTeam(player, kill, team)
if team ~= "SWAT" then
if player.Team ~= game.Teams:FindFirstChild(team) then
player.Team = game.Teams:FindFirstChild(team)
if kill == true then
player.Character.Humanoid.Health = 0
end
end
else
if MPS:UserOwnsGamePassAsync(player.UserId, 17525592) or table.find(developers, player.UserId) then
if player.Team ~= game.Teams:FindFirstChild(team) then
player.Team = game.Teams:FindFirstChild(team)
if kill == true then
player.Character.Humanoid.Health = 0
end
end
else
MPS:PromptGamePassPurchase(player, 17525592)
end
end
end
game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, kill, team)
changeTeam(player, kill, team)
end)
This is from another script and it actually works, why this doesn’t?
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts) do
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
Found = true
break
else
Found = false
end
end