What I'm up to is I'm trying to freeze players. What I want is, if the player isn't frozen, freeze the player for Time seconds. But if the player is frozen again while they are still frozen, they would be released at the latest time. For example, if they are frozen for 10 seconds now and 2 seconds later they are frozen again for 5 seconds, release them 10 seconds later, not 7. I tried to code that, and it is really hard to test. Should this work?
FrozenChars = {}
return function(Char, Time)
local Parts = Char:GetChildren()
local CurrReleaseTime = tick()+Time
if not FrozenChars[Char] then
FrozenChars[Char] = CurrReleaseTime
for _, v in pairs(Parts) do
if v:IsA("BasePart") and v ~= Char.PrimaryPart then
v.Anchored = true
end
end
elseif CurrReleaseTime > FrozenChars[Char] then
FrozenChars[Char] = CurrReleaseTime
end
delay(Time, function()
wait()
if CurrReleaseTime >= FrozenChars[Char] then
for _, v in pairs(Parts) do
if v:IsA("BasePart") and v ~= Char.PrimaryPart then
v.Anchored = false
end
end
FrozenChars[Char] = nil
end
end)
end
