-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAfk.lua
58 lines (48 loc) · 1.76 KB
/
Afk.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
repeat wait(.25) until game:IsLoaded() and game.Players.LocalPlayer.Character
repeat wait(1) until game:GetService('Players').LocalPlayer.Character:FindFirstChild('HumanoidRootPart')
-- game.Players.LocalPlayer.Character
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local afkThreshold = 1
local afkTimeThreshold = 300
local function calculateDistance(point1, point2)
local dx = point2.X - point1.X
local dy = point2.Y - point1.Y
local dz = point2.Z - point1.Z
return math.sqrt(dx^2 + dy^2 + dz^2)
end
local function onPositionChanged()
local character = LocalPlayer.Character
if not character or not character:FindFirstChild("HumanoidRootPart") then
return
end
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local lastPosition = humanoidRootPart.Position
local afkTime = 0
-- humanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
-- end)
local currentPosition
while true do
pcall(function()
currentPosition = humanoidRootPart.Position
local distance = calculateDistance(currentPosition, lastPosition)
if distance > afkThreshold then
afkTime = 0
else
afkTime = afkTime + 1
if afkTime >= afkTimeThreshold then
LocalPlayer:Kick("Kich vi dam me")
end
end
lastPosition = currentPosition
end)
wait(.5)
end
end
spawn(function()
local success, result = pcall(onPositionChanged)
if not success then
LocalPlayer:Kick("Error when connecting Position changed: " .. tostring(result))
end
end)