Hello!
Sorry for my English, I use a translator. Everything written in this post is just a hint or an idea.
This problem is solved in many ways(choose for yourself). I’ll give you some code examples that work
Since you need to kill or teleport players in cold blood, we will work with the server.
Since the Character is a model, we can use the function :moveTo(Position) to teleport it(some may find this method rude and dangerous when teleporting, but I use it as an example)
We can kill Players by nullifying the Humanoid’s health
To find out who is in which zone, I suggest you use:
BasePart.Touched-Track the characters ’ location in a specific location, then teleport or die
workspace:FindPartsInRegion 3-Identify all objects in the specified “zone”.
In the first example, I connect the touch event for a while, putting everything in an array. After waiting for the timer, I disable all events and decide to “kill or teleport”."
By default, undecided players die.
--Services
local Players = game:GetService('Players')
--------------
local KillZone = nil ---- Здесь должна быть ссылка на зону смерти
local TeleportZone = nil -- Здесь должна быть ссылка на зону телепортации
local TeleportTo = Vector3.new(0,0,0) --- Куда телепортировать игроков
---------------------
local Court = {}
function Court:get_characters()
local chars = {}
for _,player in ipairs(Players:GetChildren()) do
if player.Character then
table.insert(chars,player.Character)
else
----- Участь незагруженного игрока пр суде
end
end
return chars
end
function Court:teleport(character)
character:MoveTo(TeleportTo)
end
function Court:kill_hum(hum)
hum.Health = 0
end
function Court:watch_time(Time)
local TouchedList = {}
local AllEvents = {}
for _,character in ipairs(Court:get_characters()) do
table.insert(AllEvents,{character.PrimaryPart.Touched:Connect(function(obj)
if obj == KillZone and table.find(TouchedList, character.Name) then
table.remove(TouchedList,table.find(TouchedList, character.Name))
end
if obj == TeleportZone then
table.insert(TouchedList, character.Name)
end
end),
character.PrimaryPart.TouchEnded:Connect(function(obj)
-- if obj == KillZone or obj == TeleportZone and table.find(TouchedList, --character.Name) then
-- table.remove(TouchedList,table.find(TouchedList,character.Name))
---end
end)
})
end
wait(Time)
for _,double_event in ipairs(AllEvents) do
if double_event[0] and double_event[1] then
double_event[0]:Disconnect()
double_event[1]:Disconnect()
end
end
return TouchedList
end
function Court:_touchlist(touchlist)
for _,char in ipairs(Court:get_characters()) do
local humanoid = char:FindFirstChildOfClass('Humanoid')
if humanoid then
if table.find(touchlist,char.Name) then
Court:teleport(char)
else
Court:kill_hum(humanoid)
end
end
end
end
function Court.new(Time)
local TouchList = Court:watch_time(Time)
Court:_touchlist(TouchList)
end
wait(15)
Court.new(10) --- Через 10 секунд умрут, те кто не решился или пошел не туда...
-
Works under the condition that players are born in the workspace.
In this example, I don’t bother too much and by the time the time comes, I just read all the objects in the given Region 3
--Services
local Players = game:GetService('Players')
--------------
local KillZone = nil ---- Здесь должна быть ссылка на зону смерти
local TeleportZone = nil -- Здесь должна быть ссылка на зону телепортации
local TeleportTo = Vector3.new(0,0,0) --- Куда телепортировать игроков
-----------------
local Court = {}
function Court:teleport(character)
character:MoveTo(TeleportTo)
end
function Court:kill_hum(hum)
hum.Health = 0
end
function Court:check_teleport()
local chars = {}
local min = TeleportZone.Position - (0.5 * TeleportZone.Size)
local max = TeleportZone.Position + (0.5 * TeleportZone.Size)
local region = Region3.new(min, max)
local parts = workspace:FindPartsInRegion3(region, TeleportZone)
for _,part in ipairs(parts)do
if not(table.find(chars,part.Parent.Name)) and Players:FindFirstChild(part.Parent.Name) then
table.insert(chars,part.Parent.Name)
end
end
return chars
end
function Court:check_kill()
local chars = {}
local min = KillZone.Position - (0.5 * KillZone.Size)
local max = KillZone.Position + (0.5 * KillZone.Size)
local region = Region3.new(min, max)
local parts = workspace:FindPartsInRegion3(region, KillZone)
for _,part in ipairs(parts)do
if not(table.find(chars,part.Parent.Name)) and Players:FindFirstChild(part.Parent.Name) then
table.insert(chars,part.Parent.Name)
end
end
return chars
end
function Court.new(Time)
wait(Time)
local kill_chars=Court:check_kill()
local teleport_chars = Court:check_teleport()
for _,char_name in ipairs(teleport_chars) do
if workspace:FindFirstChild(char_name) then
local char=workspace:FindFirstChild(char_name)
local humanoid = char:FindFirstChildOfClass('Humanoid')
if humanoid then
Court:teleport(char)
end
end
end
for _,char_name in ipairs(kill_chars) do
if workspace:FindFirstChild(char_name) then
local char=workspace:FindFirstChild(char_name)
local humanoid = char:FindFirstChildOfClass('Humanoid')
if humanoid then
Court:kill_hum(humanoid)
end
end
end
return kill_chars,teleport_chars
end
wait(10)
Court.new(10)