Wassup guys. This is my second time creating a topic in roblox!
Anyways, I need help: I want to make a script that if a player opens chat, or presses escape to menu, or switches other tabs from roblox, he will freeze, But if closes chat, closes the menu, or switches back to the roblox tab, he will be unfreezed. It’s like an afk, but he instead freezes. Can you guys help me?
local UIS = game:GetService("UserInputService")
local GuiS = game:GetService("GuiService")
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local defaultWalkSpeed, defaultJumPower = hum.WalkSpeed, hum.JumpPower
local lastWalkSpeed, lastJumpPower
local isFreeze = false
local function freeze()
if isFreeze then return end
isFreeze = true
lastWalkSpeed = hum.WalkSpeed
lastJumpPower = hum.JumpPower
hum.WalkSpeed = 0
hum.JumpPower = 0
end
local function unfreeze()
if not isFreeze then return end
isFreeze = false
hum.WalkSpeed = lastWalkSpeed or defaultWalkSpeed
hum.JumpPower = lastJumpPower or defaultJumpPower
end
UIS.TextBoxFocused:Connect(freeze)
UIS.WindowFocused:Connect(freeze)
GuiS.MenuOpened:Connect(freeze)
UIS.TextBoxFocusReleased:Connect(unfreeze)
UIS.WindowFocusReleased:Connect(unfreeze)
GuiS.MenuClosed:Connect(unfreeze)