I’m creating a gamemode similar to TF2 payload.
Everything works fine, however I am unable to come up with a good method of stopping the payload and resuming it based on the number of players of each team are near the cart.
This has had me stumped for a long while, so any help at all is appreciated.
local tweenService = game:GetService("TweenService")
local pointsChildren = script.Parent.Parent.Waypoints:GetDescendants()
local StartPart = script.Parent.Parent.Waypoints.StartPart
local OrderByDistance = {}
local Part = script.Parent.Parent.BasePart
local Module = require(script.ModuleScript)
local CanMove = false
local tweenInfo = TweenInfo.new(
10,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
while #pointsChildren > 0 do
local lastIndex = nil
local closestPart = nil
local PreviousDistance = nil
for i, v in ipairs(pointsChildren) do
if v:IsA("Part") and v ~= StartPart then
local distance = (StartPart.Position - v.Position).Magnitude
if closestPart == nil then
closestPart = v
PreviousDistance = distance
lastIndex = i
else
if distance < PreviousDistance then
closestPart = v
PreviousDistance = distance
lastIndex = i
end
end
end
end
StartPart = closestPart
table.insert(OrderByDistance, closestPart)
table.remove(pointsChildren, lastIndex)
end
local check = coroutine.wrap(function()
while wait(0.1) do
if #Module:ATTACKERSNUM() > 0 and #Module:DEFENDERSNUM() <= 0 then
CanMove = true
elseif #Module:ATTACKERSNUM() <= 0 and #Module:DEFENDERSNUM() > 0 then
CanMove = false
elseif #Module:ATTACKERSNUM() == 0 and #Module:DEFENDERSNUM() == 0 then
CanMove = false
end
print(#Module:ATTACKERSNUM())
print(#Module:DEFENDERSNUM())
end
end)
check()
while true do
for _, v in ipairs(OrderByDistance) do
v.Material = Enum.Material.Neon
task.wait(0.1)
v.Material = Enum.Material.Plastic
local Goal = {}
Goal.Position = v.Position
Goal.Orientation = v.Orientation
local tween = tweenService:Create(Part,tweenInfo,Goal)
if CanMove then
tween:Play()
else
tween:Pause()
end
tween.Completed:Wait()
end
end