Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Will this work for correctly freezing and unfreezing players?

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

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.