-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesync.lua
More file actions
145 lines (122 loc) · 3.38 KB
/
desync.lua
File metadata and controls
145 lines (122 loc) · 3.38 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local espTransparency = 0.25
local function getRoot(char)
return char:FindFirstChild("HumanoidRootPart")
end
local function getPing()
local stats = game:GetService("Stats")
local network = stats.Network
if network and network.ServerStatsItem then
local pingStat = network.ServerStatsItem["Data Ping"]
if pingStat then
return math.floor(pingStat:GetValue())
end
end
return 0
end
local function createDelayedClone()
local char = LocalPlayer.Character
if not char then return end
local root = getRoot(char)
if not root then return end
local oldClone = workspace:FindFirstChild("DelayedClone")
if oldClone then
oldClone:Destroy()
end
local clone = Instance.new("Model")
clone.Name = "DelayedClone"
clone.Parent = workspace
local parts = {}
for _, part in pairs(char:GetChildren()) do
if part:IsA("BasePart") and part.Name == "HumanoidRootPart" then
local partClone = part:Clone()
for _, v in pairs(partClone:GetChildren()) do
if not v:IsA("SpecialMesh") then
v:Destroy()
end
end
partClone.Anchored = true
partClone.CanCollide = false
partClone.Transparency = espTransparency
partClone.Parent = clone
parts[part.Name] = partClone
end
end
local cframeHistory = {}
local historyMaxSize = 60
local smoothedPing = getPing()
local lastUpdateTime = os.clock()
local function getSmoothedPing()
local currentPing = getPing()
smoothedPing = smoothedPing * 0.8 + currentPing * 0.2
return smoothedPing
end
RunService.RenderStepped:Connect(function(dt)
local currentTime = os.clock()
local timeSinceLastUpdate = currentTime - lastUpdateTime
if timeSinceLastUpdate < 0.05 then
return
end
lastUpdateTime = currentTime
local ping = getSmoothedPing() / 1000
local targetDelay = math.clamp(ping, 0.1, 0.5)
local currentCFrames = {}
for name, part in pairs(parts) do
local originalPart = char:FindFirstChild(name)
if originalPart then
currentCFrames[name] = originalPart.CFrame
end
end
table.insert(cframeHistory, {
time = currentTime,
cframes = currentCFrames
})
for i = #cframeHistory, 1, -1 do
if currentTime - cframeHistory[i].time > 1 then
table.remove(cframeHistory, i)
end
end
while #cframeHistory > historyMaxSize do
table.remove(cframeHistory, 1)
end
if #cframeHistory > 1 then
local targetTime = currentTime - targetDelay
local closestFrame = nil
local closestDiff = math.huge
for i = 1, #cframeHistory do
local frame = cframeHistory[i]
local timeDiff = math.abs(frame.time - targetTime)
if timeDiff < closestDiff then
closestDiff = timeDiff
closestFrame = frame
end
end
if closestFrame then
for name, part in pairs(parts) do
if closestFrame.cframes[name] then
part.CFrame = part.CFrame:Lerp(closestFrame.cframes[name], 0.9)
end
end
end
end
end)
end
LocalPlayer.CharacterAdded:Connect(function(character)
local oldClone = workspace:FindFirstChild("DelayedClone")
if oldClone then
oldClone:Destroy()
end
task.wait(1)
createDelayedClone()
end)
LocalPlayer.CharacterRemoving:Connect(function()
local oldClone = workspace:FindFirstChild("DelayedClone")
if oldClone then
oldClone:Destroy()
end
end)
if LocalPlayer.Character then
createDelayedClone()
end