View difference between Paste ID: hk10vpkx and bvfniurH
SHOW: | | - or go back to the newest paste.
1
local plrs=game:FindFirstChildOfClass("Players")
2
local rs=game:FindFirstChildOfClass("RunService")
3
local ws=game:FindFirstChildOfClass("Workspace")
4
local uis=game:FindFirstChildOfClass("UserInputService")
5
local gs=game:FindFirstChildOfClass("GuiService")
6
local cg=game:FindFirstChildOfClass("CoreGui")
7
8
local lp=plrs.LocalPlayer
9
local pg=lp:FindFirstChildOfClass("PlayerGui")
10
local mouse=lp:GetMouse()
11
local stepped=rs.Stepped
12
local heartbeat=rs.Heartbeat
13
local renderstepped=rs.RenderStepped
14
15
local osclock=os.clock
16
local tspawn=task.spawn
17
local twait=task.wait
18
local schar=string.char
19
local sbyte=string.byte
20
local ssub=string.sub
21
local sfind=string.find
22
local supper=string.upper
23
local mrandom=math.random
24
local clamp=math.clamp
25
local sin=math.sin
26
local cos=math.cos
27
local abs=math.abs
28
local rad=math.rad
29
local tinsert=table.insert
30
local tclear=table.clear
31
local tfind=table.find
32
local tunpack=table.unpack
33
34
local i=Instance.new 
35
local v2=Vector2.new 
36
local v3=Vector3.new
37
local c3=Color3.new 
38
local cf=CFrame.new
39
local angles=CFrame.Angles
40
local u2=UDim2.new
41
local e=Enum 
42
local cs=ColorSequence.new 
43
local csk=ColorSequenceKeypoint.new 
44
45
local sine=osclock()
46
local deltaTime=0
47
local v3_0=v3(0,0,0)
48
local v3_101=v3(1,0,1)
49
local v3_010=v3(0,1,0)
50
local v3_001=v3(0,0,1)
51
local cf_0=cf(0,0,0)
52
local v3_xz=v3_101*10
53
local v3_net=v3_010*25.01
54
55
local function makepcall(f)
56
	if type(f)=="function" then
57
		return function(...)
58
			local a={...}
59
			local r=nil
60
			pcall(function()
61
				r={f(tunpack(a))}
62
			end)
63
			return tunpack(r or {})
64
		end
65
	end
66
	return function() end
67
end
68
local function rs(l) 
69
	l=l or mrandom(8,15) 
70
	local s="" 
71
	for i=1,l do 
72
		if mrandom(1,2)==1 then 
73
			s=s..schar(mrandom(65,90)) 
74
		else 
75
			s=s..schar(mrandom(97,122)) 
76
		end 
77
	end 
78
	return s 
79
end 
80
local function gp(p,n,cl)
81
	if typeof(p)=="Instance" then
82
		local c=p:GetChildren()
83
		for i=1,#c do
84
			local v=c[i]
85
			if (v.Name==n) and v:IsA(cl) then
86
				return v
87
			end
88
		end
89
	end
90
	return nil
91
end
92
local function loopgp(...)
93
	while true do
94
		local r=gp(...)
95
		if r then
96
			return r
97
		end
98
		twait()
99
	end
100
end
101
local function timegp(p,n,c,t)
102
	t=osclock()+t
103
	while t>osclock() do
104
		local r=gp(p,n,c)
105
		if r then
106
			return r
107
		end
108
		twait()
109
	end
110
	return nil
111
end
112
local function getNetlessVelocity(realVel)
113
	--if true then return v3_0 end
114
	--if true then return realPartVelocity end
115
	--if true then return v3_net end
116
	if realVel.Magnitude>25.01 then
117
		realVel=realVel.Unit*25.01
118
	end
119
	return realVel*v3_xz+v3_net
120
end
121
local isClientInstance=makepcall(function(i)
122
	return ssub(i:GetDebugId(),1,1)=="0"
123
end)
124
local isServerInstance=function(i)
125
	return not isClientInstance(i)
126
end
127
local shp=(((type(getfenv)=="function") and getfenv()) or {}).sethiddenproperty
128
129
local allowshiftlock=nil
130
local ctrltp=nil
131
local simrad=nil
132
local placeholders=nil
133
local clickfling=nil
134
135
local stopreanimate=function() return nil end
136
local function reanimate()
137
	--[[
138
	    FDless reanimate by MyWorld
139
	    aka no client sided instances
140
	    "what else do i optimize here"
141
	]]
142
143
	local novoid = true --prevents parts from going under workspace.FallenPartsDestroyHeight if you control them
144
	local placeholders = true --makes client sided accessories replacing the real ones when unavailable
145
	local speedlimit = 3000 --makes your parts move slower if the magnitude of their velocity is higher than this
146
	local antiragdoll = true --removes instances that are usually used for ragdolling form your character
147
	local addPartsOnRun = false --allows u to add more parts and joints to the simulation after it started
148
	local R15toR6 = true --adds fake r6 parts and joints for animations if your character is r15
149
	local walkSpeed = 16 --your walkspeed (can be changed at runtime)
150
	local jumpPower = 50 --your jump power (can be changed at runtime)
151
	local allowshiftlock = true --allows the user to use shiftlock (can be changed at runtime)
152
	local gravity = 196.2 --how fast the characters velocity increases while falling (can be changed at runtime)
153
	local simrad = "shp" --sets simulation radius to this with sethiddenproperty if its set to a number
154
	local ctrlclicktp = false --makes you teleport where u point ur mouse cursor at when click and hold ctrl down
155
	local clickfling = true --makes you fling the person you clicked when its available to do so
156
	local flingvel = v3(16000,16000,16000) --the rotation velocity that ur character will have while flinging
157
158
	local c=lp.Character
159
	if stopreanimate() or not (c and c:IsDescendantOf(ws)) then return end
160
	
161
	local hum=c:FindFirstChildOfClass("Humanoid")
162
	local rootpart=gp(c,"HumanoidRootPart","BasePart") or gp(c,"Torso","BasePart") or gp(c,"UpperTorso","BasePart") or (hum and hum.RootPart) or timegp(c,"HumanoidRootPart","BasePart",0.5) or c:FindFirstChildWhichIsA("BasePart")
163
	if not rootpart then return end
164
165
	R15toR6=R15toR6 and hum and (hum.RigType==e.HumanoidRigType.R15)
166
	simrad = (type(simrad)=="number") and (type(shp)=="function") and simrad
167
168
	local flingparts={}
169
	local cam=nil
170
	--theres a way to have ws.currentcamera nil on heartbeat and still have the game run normally
171
	local function refcam()
172
		cam=ws.CurrentCamera
173
		while not cam do
174
			ws:GetPropertyChangedSignal("CurrentCamera"):Wait()
175
			cam=ws.CurrentCamera
176
		end
177
	end
178
	refcam()
179
	local camcf=cam.CFrame
180
	local enumCamS=e.CameraType.Scriptable
181
	local camt=cam.CameraType
182
	local camcon0=nil
183
	local camcon1=nil
184
	local function onnewcamera()
185
		refcam()
186
		if camcon0 then 
187
			camcon0:Disconnect()
188
			camcon0=nil
189
		end
190
		if not c then 
191
			if cam.CameraType==enumCamS then
192
				cam.CameraType=camt
193
			end
194
			return camcon1:Disconnect() 
195
		end
196
		camcon0=cam.Changed:Connect(function(p)
197
			if not c then
198
				camcon0:Disconnect()
199
				return camcon1:Disconnect()
200
			end
201
			if (p=="CFrame") and (cam.CFrame~=camcf) then
202
				cam.CFrame=camcf
203
			elseif (p=="CameraSubject") or (p=="CameraType") then
204
				local subj=cam.CameraSubject
205
				if subj and subj:IsA("Humanoid") and (subj.Parent==c) and (cam.CameraType~=enumCamS) then
206
					cam.CameraType = enumCamS
207
				end
208
			end
209
		end)
210
		local subj=cam.CameraSubject
211
		if subj and subj:IsA("Humanoid") and (subj.Parent==c) and (cam.CameraType~=enumCamS) then
212
			cam.CameraType=enumCamS
213
		end
214
		cam.CFrame=camcf
215
	end
216
	camcon1=ws:GetPropertyChangedSignal("CurrentCamera"):Connect(onnewcamera)
217
	onnewcamera()
218
219
	local fpdh=ws.FallenPartsDestroyHeight
220
	novoid=novoid and (fpdh+1)
221
	
222
	local function getMeshOfPart(v)
223
		if typeof(v)=="Instance" then
224
			if v:IsA("MeshPart") then
225
				return v.MeshId, v.TextureID
226
			else
227
				v=v:FindFirstChildOfClass("SpecialMesh")
228
				if v then
229
					return v.MeshId, v.TextureId
230
				end
231
			end
232
		end
233
		return nil, nil
234
	end
235
	
236
	local joints={}
237
	local cframes={}
238
	local des=c:GetDescendants()
239
	for i=1,#des do
240
		local v=des[i]
241
		if v:IsA("JointInstance") then
242
			tinsert(joints,{
243
				Name=v.Name,
244
				C0=v.C0,
245
				C1=v.C1,
246
				Part0=v.Part0,
247
				Part1=v.Part1
248
			})
249
		elseif v:IsA("BasePart") then
250
			cframes[v]=v.CFrame
251
		end
252
	end
253
	
254
	local function makeplaceholder(v)
255
		if typeof(v)~="Instance" then
256
			return nil
257
		end
258
		if not v.Archivable then
259
			v.Archivable=true
260
		end
261
		v=v:Clone()
262
		local c=v:GetChildren()
263
		for i=1,#c do
264
			local v=c[i]
265
			if v:IsA("SpecialMesh") then
266
				v.Name=rs()
267
				v:ClearAllChildren()
268
			else
269
				v:Destroy()
270
			end
271
		end
272
		v.Name=rs()
273
		v.Anchored=true
274
		v.CanCollide=false
275
		v.Transparency=0.25
276
		v.Parent=ws
277
		return v
278
	end
279
	
280
	local function filterInstance(v)
281
		local ins=v
282
		if isClientInstance(v) then
283
			v={CFrame=v.CFrame,Name=v.Name,Anchored=true}
284
		else
285
			local meshid,textureid=getMeshOfPart(v)
286
			if meshid and (meshid~="") and textureid and (textureid~="") then
287
				if placeholders then
288
					v={CFrame=v.CFrame,Name=v.Name,Anchored=true,meshid=meshid,textureid=textureid,placeholder=makeplaceholder(v)}
289
				else
290
					v={CFrame=v.CFrame,Name=v.Name,Anchored=true,meshid=meshid,textureid=textureid}
291
				end
292
			else
293
				v={CFrame=v.CFrame,Name=v.Name,Anchored=true}
294
			end
295
		end
296
		local check=ins~=v
297
		while check do
298
			check=false
299
			for i,v1 in pairs(cframes) do
300
				if i==ins then
301
					cframes[ins]=nil
302
					cframes[v]=v1
303
					check=true
304
					break
305
				end
306
			end
307
		end
308
		for i,v1 in pairs(joints) do
309
			if v1.Part0==ins then
310
				v1.Part0=v
311
			elseif v1.Part1==ins then
312
				v1.Part1=v
313
			end
314
		end
315
		if rootpart==ins then
316
			rootpart=v
317
		end
318
		return v
319
	end
320
	for i,v in pairs(joints) do
321
		v.Part0=filterInstance(v.Part0)
322
		v.Part1=filterInstance(v.Part1)
323
	end
324
	
325
	local Yvel=0
326
	local cfr=rootpart.CFrame
327
	local pos=cfr.Position
328
	local shiftlock=false
329
	local firstperson=false
330
	local xzvel=v3_0
331
	local v3_0150=v3_010*1.5
332
	local camoff=cf(v3_0,camcf.LookVector)
333
	camoff=camoff-v3_001*(camcf.Position-(pos+v3_0150)).Magnitude
334
335
	local refreshjointsinternal=nil
336
	refreshjointsinternal=function(part,refreshed)
337
		if not part then return end
338
		tinsert(refreshed,part)
339
		for i,v in pairs(joints) do
340
			local part0=v.Part0
341
			local part1=v.Part1
342
			if part1 and (part0==part) then
343
				cframes[part1]=cframes[part]*v.C0*v.C1:Inverse()
344
				if not tfind(refreshed,part1) then
345
					refreshjointsinternal(part1,refreshed)
346
				end
347
			elseif part0 and (part1==part) then
348
				cframes[part0]=cframes[part]*v.C1*v.C0:Inverse()
349
				if not tfind(refreshed,part0) then
350
					refreshjointsinternal(part0,refreshed)
351
				end
352
			end
353
		end
354
	end
355
	local function refreshjoints(v)
356
		refreshjointsinternal(v,{})
357
	end
358
359
	if R15toR6 then
360
		local R6parts={ 
361
			head={Name="Head",Anchored=true},
362
			torso={Name="Torso",Anchored=true},
363
			root={Name="HumanoidRootPart",Anchored=true},
364
			leftArm={Name="Left Arm",Anchored=true},
365
			rightArm={Name="Right Arm",Anchored=true},
366
			leftLeg={Name="Left Leg",Anchored=true},
367
			rightLeg={Name="Right Leg",Anchored=true}
368
		}
369
		for i,v in pairs(R6parts) do
370
			cframes[v]=cfr
371
		end
372
		tinsert(joints,{
373
			Name="Neck",
374
			Part0=R6parts.torso,Part1=R6parts.head,
375
			C0=cf(0,1,0,-1,0,0,0,0,1,0,1,-0),
376
			C1=cf(0,-0.5,0,-1,0,0,0,0,1,0,1,-0)
377
		})
378
		tinsert(joints,{
379
			Name="RootJoint",
380
			Part0=R6parts.root,Part1=R6parts.torso,
381
			C0=cf(0,0,0,-1,0,0,0,0,1,0,1,-0),
382
			C1=cf(0,0,0,-1,0,0,0,0,1,0,1,-0)
383
		})
384
		tinsert(joints,{
385
			Name="Right Shoulder",
386
			Part0=R6parts.torso,Part1=R6parts.rightArm,
387
			C0=cf(1,0.5,0,0,0,1,0,1,-0,-1,0,0),
388
			C1=cf(-0.5,0.5,0,0,0,1,0,1,-0,-1,0,0)
389
		})
390
		tinsert(joints,{
391
			Name="Left Shoulder",
392
			Part0=R6parts.torso,Part1=R6parts.leftArm,
393
			C0=cf(-1,0.5,0,0,0,-1,0,1,0,1,0,0),
394
			C1=cf(0.5,0.5,0,0,0,-1,0,1,0,1,0,0)
395
		})
396
		tinsert(joints,{
397
			Name="Right Hip",
398
			Part0=R6parts.torso,Part1=R6parts.rightLeg,
399
			C0=cf(1,-1,0,0,0,1,0,1,-0,-1,0,0),
400
			C1=cf(0.5,1,0,0,0,1,0,1,-0,-1,0,0)
401
		})
402
		tinsert(joints,{
403
			Name="Left Hip" ,
404
			Part0=R6parts.torso,Part1=R6parts.leftLeg,
405
			C0=cf(-1,-1,0,0,0,-1,0,1,0,1,0,0),
406
			C1=cf(-0.5,1,0,0,0,-1,0,1,0,1,0,0)
407
		})
408
		tinsert(joints,{
409
			Part0=R6parts.root,Part1=rootpart,
410
			C0=cf_0,C1=cf_0
411
		})
412
		refreshjoints(rootpart)
413
		local function getpart(n)
414
			for i,_ in pairs(cframes) do
415
				if (i.Name==n) and (type(i)~="table") then
416
					return i
417
				end
418
			end
419
			return nil
420
		end
421
		local function makejoint(p0, p1, p2)
422
			p1=getpart(p1)
423
			p2=getpart(p2)
424
			if not (p1 and p2) then return end
425
			for i,v in pairs(joints) do
426
				if (v.Part0==p1) and (v.Part1==p2) then
427
					joints[i]=nil
428
				elseif (v.Part0==p2) and (v.Part1==p1) then
429
					joints[i]=nil
430
				end
431
			end
432
			tinsert(joints,{
433
				Part0=p0,Part1=p1,
434
				C0=cf_0,
435
				C1=cframes[p1]:Inverse()*cframes[p0]
436
			})
437
		end
438
		makejoint(R6parts.head,"Head","UpperTorso")
439
		makejoint(R6parts.leftArm,"LeftUpperArm","UpperTorso")
440
		makejoint(R6parts.rightArm,"RightUpperArm","UpperTorso")
441
		makejoint(R6parts.leftLeg,"LeftUpperLeg","LowerTorso")
442
		makejoint(R6parts.rightLeg,"RightUpperLeg","LowerTorso")
443
		makejoint(R6parts.torso,"LowerTorso","HumanoidRootPart")
444
	end
445
		
446
	local function getPart(name,blacklist)
447
		for i,v in pairs(cframes) do
448
			if (i.Name==name) and not (blacklist and tfind(blacklist,i)) then
449
				return i
450
			end
451
		end
452
		return nil
453
	end
454
455
	local function getPartFromMesh(meshid,textureid,blacklist)
456
		for v,_ in pairs(cframes) do
457
			if (type(v)=="table") and not (blacklist and tfind(blacklist,v)) then
458
				if v.meshid and sfind(v.meshid,meshid) and sfind(v.textureid,textureid) then
459
					return v
460
				end
461
			end
462
		end
463
		return nil
464
	end
465
466
	local function getJoint(name)
467
		for i,v in pairs(joints) do
468
			if v.Name==name then
469
				return v
470
			end
471
		end
472
		return {C0=cf_0,C1=cf_0}
473
	end
474
475
	local function getPartJoint(handle)
476
		for i,v in pairs(joints) do
477
			if v.Part0==handle then
478
				return v
479
			end
480
		end
481
		for i,v in pairs(joints) do
482
			if v.Part1==handle then
483
				return v
484
			end
485
		end
486
		return nil
487
	end
488
489
	local accessorylimbs={
490
        -- paid aligning --
491
		{meshid="12344207333",textureid="12344207341",C0=angles(115,0,0),Name="Left Arm"},  -- Moving Left Arm [White]
492
		{meshid="12344206657",textureid="12344206675",C0=angles(115,0,0),Name="Right Arm"}, -- Moving Right Arm [White]
493
		{meshid="14255522247",textureid="14255543546",C0=angles(0,0,1.5707963267948966),Name="Left Leg"}, -- Blocky Left Leg [White]
494
		{meshid="14255522247",textureid="14255543546",C0=angles(0,0,1.5707963267948966),Name="Right Leg"}, -- Blocky Right Leg [White]
495
		{meshid="14241018198",textureid="14251599953",C0=cf_0,Name="Torso"}, -- Torso Extension
496
		{meshid="11159370334",textureid="11159284657",C0=angles(0,0,1.5707963267948966),Name="Right Leg"}, -- Dummy Head1
497
		{meshid="11263221350",textureid="11263219250",C0=angles(0,0,1.5707963267948966),Name="Left Leg"}, -- Dummy Head2
498
499
        -- free aligning --
500
	    {meshid="8761442057",textureid="8761547598",C0=angles(115,0,0),Name="Left Arm"}, -- Yoga Mat1
501
		{meshid="8761442057",textureid="8761421987",C0=angles(115,0,0),Name="Right Arm"}, -- Yoga Mat2
502
		{meshid="9867442567",textureid="9867451480",C0=angles(0,0,-15),Name="Left Leg"}, -- Rouge Bag1
503
		{meshid="9867442661",textureid="9867451480",C0=angles(0,0,-15),Name="Right Leg"}, -- Rouge Bag2
504
		{meshid="4819720316",textureid="4819722776",C0=angles(0,0,-105),Name="Torso"}, -- Robox
505
        
506
        -- free aligning, fedoras --
507
	    {meshid="3030546036",textureid="3033903209",C0=angles(115,0,0),Name="Left Arm"},
508
		{meshid="3030546036",textureid="3360978739",C0=angles(115,0,0),Name="Right Arm"},
509
		{meshid="3030546036",textureid="3409604993",C0=angles(115,-115,0),Name="Left Leg"},
510
		{meshid="3030546036",textureid="3033898741",C0=angles(115,115,0),Name="Right Leg"}
511
	}
512
513
	local alignblacklist={}
514
	for i=1,#accessorylimbs do
515
		local v=accessorylimbs[i]
516
		local p=getPart(v.Name)
517
		local h=getPartFromMesh(v.meshid,v.textureid,alignblacklist)
518
		local w=getPartJoint(h)
519
		if p and w then
520
			w.C0=v.C0
521
			w.Part0=h
522
			w.C1=cf_0
523
			w.Part1=p
524
			tinsert(alignblacklist,h)
525
		end
526
	end
527
		
528
	local raycastparams=RaycastParams.new()
529
	raycastparams.FilterType=e.RaycastFilterType.Blacklist
530
	raycastparams.RespectCanCollide=true
531
	local rayfilter={}
532
	local characters={}
533
	local function refreshrayfilter()
534
		tclear(rayfilter)
535
		for i,v in pairs(characters) do
536
			tinsert(rayfilter,v)
537
		end
538
		raycastparams.FilterDescendantsInstances=rayfilter
539
	end
540
	local flingtarget=nil
541
	local cframes1={}
542
	local lastpositions={}
543
	local rootparts={}
544
	local function onplayer(v)
545
		local lastc=nil
546
		local function oncharacter()
547
			local newc=v.Character
548
			if newc and (newc ~= lastc) then
549
				lastc=newc
550
				characters[v]=newc
551
				refreshrayfilter()
552
				local hrp=loopgp(newc,"HumanoidRootPart","BasePart")
553
				if v~=lp then
554
					rootparts[v]=hrp
555
				end
556
				twait()
557
				if c and (v==lp) and hrp and (hrp.Parent==newc) and newc:IsDescendantOf(ws) then
558
					local startpos=pos+v3(mrandom(-32,32),0,mrandom(-32,32))
559
					local dir=nil
560
					local poscheck=true
561
					while poscheck do
562
						poscheck=false
563
						for i,v in pairs(rootparts) do
564
							local diff=(startpos-v.Position)*v3_101
565
							if diff.Magnitude<10 then
566
								poscheck=true
567
								dir=dir or diff.Unit
568
								startpos=startpos+dir
569
							end
570
						end
571
						local diff=(startpos-pos)*v3_101
572
						if diff.Magnitude<10 then
573
							poscheck=true
574
							dir=dir or diff.Unit
575
							startpos=startpos+dir
576
						end
577
					end
578
					startpos=cfr+startpos-cfr.Position
579
					if flingtarget then
580
						local con=heartbeat:Connect(function()
581
							local idleoff=v3(sin((sine-0.0375)*16),sin(sine*16),sin((sine+0.075)*16))
582
							
583
							hrp.CFrame=flingtarget.CFrame+flingtarget.Velocity*(sin(sine*15)+1)+v3(0,-2,0)+idleoff*0.001
584
							hrp.Velocity=idleoff
585
							hrp.RotVelocity=flingvel+idleoff
586
						end)
587
						twait(0.5)
588
						con:Disconnect()
589
						flingtarget=nil
590
					end
591
					tspawn(function()
592
						local con=heartbeat:Connect(function()
593
							hrp.CFrame=startpos+v3(sin((sine-0.0375)*16),sin(sine*16),sin((sine+0.075)*16))*0.005
594
							hrp.Velocity=v3_0
595
							hrp.RotVelocity=v3_0
596
						end)
597
						twait(0.3)
598
						con:Disconnect()
599
						if newc:IsDescendantOf(ws) then
600
							tclear(cframes1)
601
							tclear(lastpositions)
602
							newc:BreakJoints()
603
							twait(0.1)
604
							local cd=newc:GetDescendants()
605
							for i,v in pairs(cframes) do
606
								if type(i)=="table" then 
607
									local meshid=i.meshid
608
									if meshid then
609
										local textureid=i.textureid
610
										for i1=1,#cd do
611
											local v=cd[i1]
612
											if v and v:IsA("BasePart") then
613
												local meshid1,textureid1=getMeshOfPart(v)
614
												if (meshid1==meshid) and (textureid1==textureid) then
615
													cd[i1]=nil
616
													cframes1[v]=i
617
													lastpositions[v]=v.Position
618
													break
619
												end
620
											end
621
										end
622
									end
623
								end
624
							end
625
						end
626
					end)
627
				end
628
			end
629
		end
630
		v:GetPropertyChangedSignal("Character"):Connect(oncharacter)
631
		oncharacter()
632
	end
633
	local plrst=plrs:GetPlayers()
634
	for i=1,#plrst do onplayer(plrst[i]) end
635
	plrs.PlayerAdded:Connect(onplayer)
636
	plrs.PlayerRemoving:Connect(function(v)
637
		characters[v]=nil
638
		rootparts[v]=nil
639
	end)
640
		
641
	local mradN05=rad(-0.5)
642
	local enumMLC=e.MouseBehavior.LockCenter
643
	local enumMB2=e.UserInputType.MouseButton2
644
	local enumMLCP=e.MouseBehavior.LockCurrentPosition
645
	local enumMD=e.MouseBehavior.Default
646
	local enumMW=e.UserInputType.MouseWheel
647
648
	local mode="default"
649
	local modes={default={}}
650
	local function addmode(key,mode)
651
		if (type(key)~="string") or (type(mode)~="table") then
652
			return
653
		end
654
		for i, v in pairs(mode) do
655
			if type(v)~="function" then
656
				mode[i]=nil
657
			end
658
		end
659
		if key=="default" then
660
			modes.default=mode
661
			if mode.modeEntered then
662
				mode.modeEntered()
663
			end
664
		elseif #key==1 then
665
			key=e.KeyCode[supper(ssub(key,1,1))]
666
			modes[key]=mode
667
		end
668
	end
669
670
	local keyW=e.KeyCode.W
671
	local keyA=e.KeyCode.A
672
	local keyS=e.KeyCode.S
673
	local keyD=e.KeyCode.D
674
	local keySpace=e.KeyCode.Space
675
	local keyShift=e.KeyCode.LeftShift
676
	local movementkeys = {
677
		[keyW]=false,
678
		[keyA]=false,
679
		[keyS]=false,
680
		[keyD]=false,
681
		[keySpace]=false
682
	}
683
	uis.InputBegan:Connect(function(a)
684
		if gs.MenuIsOpen or uis:GetFocusedTextBox() then
685
			return
686
		end
687
		a=a.KeyCode
688
		if movementkeys[a]==false then
689
			movementkeys[a]=true
690
		elseif a==keyShift then
691
			shiftlock=allowshiftlock and not shiftlock
692
		elseif modes[a] then
693
			if modes[mode].modeLeft then
694
				modes[mode].modeLeft()
695
			end
696
			if mode==a then
697
				mode="default"
698
			else
699
				mode=a
700
			end
701
			if modes[mode].modeEntered then
702
				modes[mode].modeEntered()
703
			end
704
		end
705
	end)
706
	uis.InputEnded:Connect(function(a)
707
		if movementkeys[a.KeyCode] then
708
			movementkeys[a.KeyCode]=false
709
		end
710
	end)
711
	uis.InputChanged:Connect(function(a,b)
712
		if (not b) and (a.UserInputType==enumMW) then
713
			camoff=camoff+a.Position*v3_001*(0.75-camoff.Z/4)
714
			if camoff.Z>0 then
715
				camoff=camoff-camoff.Position
716
			end
717
			firstperson=camoff.Z==0
718
		end
719
	end)
720
721
	local function fling(target,duration,rotVelocity)
722
		twait()
723
		return true --maybe later
724
	end
725
726
	local function predictionfling(target)
727
		if typeof(target)~="Instance" then 
728
			target=mouse.Target
729
			if not target then
730
				return twait() and false
731
			end
732
		end
733
		if target:IsA("Humanoid") or target:IsA("BasePart") then 
734
			target=target.Parent 
735
			if target:IsA("Accessory") then
736
				target=target.Parent
737
			end
738
		end
739
		if (not target:IsA("Model")) or (target==c) then
740
			return twait() and false
741
		end
742
		target=gp(target,"HumanoidRootPart","BasePart") or gp(target,"Torso","BasePart") or gp(target,"UpperTorso","BasePart")
743
		if not (target and target:IsDescendantOf(ws)) then
744
			return twait() and false
745
		end
746
		flingtarget=target
747
		twait()
748
		return true
749
	end
750
751
	if ctrlclicktp then
752
		ctrlclicktp=e.KeyCode.LeftControl
753
		local tpoff=v3_010*3
754
		if clickfling then
755
			mouse.Button1Down:Connect(function()
756
				if mouse.Target then
757
					if uis:IsKeyDown(ctrlclicktp) then
758
						pos=mouse.Hit.Position+tpoff
759
						cfr=cf(pos,pos+camoff.LookVector*v3_101)
760
						xzvel=v3_0
761
						Yvel=0
762
					else
763
						predictionfling()
764
					end
765
				end
766
			end)
767
		else
768
			mouse.Button1Down:Connect(function()
769
				if mouse.Target and uis:IsKeyDown(ctrlclicktp) then
770
					pos=mouse.Hit.Position+tpoff
771
					cfr=cf(pos,pos+camoff.LookVector*v3_101)
772
					xzvel=v3_0
773
					Yvel=0
774
				end
775
			end)
776
		end
777
	elseif clickfling then
778
		mouse.Button1Down:Connect(predictionfling)
779
	end
780
781
	local noYvelTime=1
782
	local lastsine=sine
783
	local pose=nil
784
	local con=nil
785
	local function mainFunction()
786
		if not c then 
787
			for i,v in pairs(cframes) do
788
				local p=i.placeholder
789
				if p then
790
					p:Destroy()
791
				end
792
			end
793
			uis.MouseBehavior=enumMD
794
			onnewcamera()
795
			local c=lp.Character
796
			if c then
797
				cam.CameraSubject=c:FindFirstChildOfClass("Humanoid")
798
			end
799
			return con and con:Disconnect() 
800
		end
801
802
		sine=osclock()
803
		local delta=sine-lastsine
804
		deltaTime=clamp(delta*10,0,1)
805
		lastsine=sine
806
807
		if shiftlock then
808
			if allowshiftlock then
809
				uis.MouseBehavior=enumMLC
810
				local rotation=uis:GetMouseDelta()*mradN05
811
				local camoffpos=camoff.Position
812
				camoff=cf(camoffpos,camoffpos+camoff.LookVector)*angles(rotation.Y,rotation.X,0)
813
			else
814
				shiftlock=false
815
			end
816
		elseif firstperson then
817
			uis.MouseBehavior=enumMLC
818
			local rotation=uis:GetMouseDelta()*mradN05
819
			local camoffpos=camoff.Position
820
			camoff=cf(camoffpos,camoffpos+camoff.LookVector)*angles(rotation.Y,rotation.X,0)
821
		elseif uis:IsMouseButtonPressed(enumMB2) then
822
			uis.MouseBehavior=enumMLCP
823
			local rotation=uis:GetMouseDelta()*mradN05
824
			local camoffpos=camoff.Position
825
			camoff=cf(camoffpos,camoffpos+camoff.LookVector)*angles(rotation.Y,rotation.X,0)
826
		else
827
			uis.MouseBehavior=enumMD
828
		end
829
830
		local raycastresult=ws:Raycast(pos,v3_010*(fpdh-pos.Y),raycastparams)
831
		local onground=nil
832
		if raycastresult then
833
			raycastresult=raycastresult.Position
834
			onground=(pos.Y-raycastresult.Y)<3.01
835
			if onground then
836
				Yvel=0
837
				cfr=cfr+v3_010*(raycastresult.Y+3-pos.Y)*clamp(delta*20,0,1)
838
				if movementkeys[keySpace] then
839
					Yvel=jumpPower
840
				end
841
			else
842
				Yvel=Yvel-gravity*delta
843
				if pos.Y+Yvel*delta<raycastresult.Y then
844
					Yvel=0
845
					cfr=cfr+v3_010*(raycastresult.Y+3-pos.Y)
846
				end
847
			end
848
		else
849
			Yvel=0
850
			onground=false
851
		end
852
		xzvel=v3_0
853
		if movementkeys[keyW] then
854
			xzvel=xzvel+(camoff.LookVector*v3_101).Unit
855
		end
856
		if movementkeys[keyS] then
857
			xzvel=xzvel-(camoff.LookVector*v3_101).Unit
858
		end
859
		if movementkeys[keyA] then
860
			xzvel=xzvel-(camoff.RightVector*v3_101).Unit
861
		end
862
		if movementkeys[keyD] then
863
			xzvel=xzvel+(camoff.RightVector*v3_101).Unit
864
		end
865
		pos=cfr.Position
866
		if shiftlock or firstperson then
867
			if xzvel.Magnitude>0 then
868
				xzvel=xzvel.Unit*walkSpeed
869
			end
870
			cfr=cf(pos,pos+camoff.LookVector*v3_101)
871
		elseif xzvel.Magnitude>0 then
872
			xzvel=xzvel.Unit*walkSpeed
873
			cfr=cfr:Lerp(cf(pos,pos+xzvel),deltaTime)
874
		end
875
		cfr=cfr+(xzvel+(v3_010*Yvel))*delta
876
		pos=cfr.Position
877
878
		camcf=cf(pos,pos+camoff.LookVector)+camoff.LookVector*camoff.Z+v3_0150
879
		if shiftlock and not firstperson then
880
			camcf=camcf+camcf.RightVector*1.75
881
		end
882
		if cam then
883
			cam.CFrame=camcf
884
		end
885
886
		if onground then
887
			if xzvel==v3_0 then
888
				pose="idle"
889
			else
890
				pose="walk"
891
			end
892
		elseif Yvel>0 then
893
			pose="jump"
894
		else
895
			pose="fall"
896
		end
897
		local lerpfunc=modes[mode][pose]
898
		lerpfunc=lerpfunc or modes.default[pose]
899
		if lerpfunc then
900
			lerpfunc()
901
		end
902
		
903
		cframes[rootpart]=cfr
904
		refreshjoints(rootpart)
905
906
		if abs(Yvel)>1 then
907
			noYvelTime=0
908
		else
909
			noYvelTime=clamp(noYvelTime+delta*0.3,0,1)
910
			xzvel=xzvel*(1-noYvelTime)
911
		end
912
913
		local idlerv=v3(sin((sine-0.0375)*16),sin(sine*16),sin((sine+0.075)*16))
914
		local idleoff=idlerv*0.001
915
		
916
		for i,v in pairs(cframes) do
917
			local p=i.placeholder
918
			if p then
919
				if p.Parent~=ws then
920
					p.Parent=ws
921
				end
922
				p.CFrame=v
923
			end
924
		end
925
		for i,v in pairs(cframes1) do
926
			if (not i.Anchored) and i:IsDescendantOf(ws) then
927
				if i.ReceiveAge==0 then
928
					local p=v.placeholder
929
					if p and p.Parent then
930
						p.Parent=nil
931
					end
932
					v=cframes[v]
933
					local lastpos=lastpositions[i]
934
					local vel=(v.Position-lastpos)/delta
935
					if vel.Magnitude>speedlimit then
936
						vel=vel.Unit*speedlimit
937
						v=v+(lastpos+vel*delta)-v.Position
938
					end
939
					lastpositions[i]=v.Position
940
					if vel.Magnitude<0.15 then
941
						v=v+idleoff
942
					end
943
					if novoid and (v.Y<novoid) then
944
						v=v+v3_010*(novoid-v.Y)
945
					end
946
					i.Velocity=getNetlessVelocity(vel*noYvelTime+xzvel)
947
					i.CFrame=v
948
					i.RotVelocity=idlerv
949
				else
950
					lastpositions[i]=i.Position
951
				end
952
			end
953
		end
954
955
		if simrad then
956
			shp(lp,"SimulationRadius",simrad)
957
		end
958
	end
959
960
	con=heartbeat:Connect(mainFunction)
961
	mainFunction()
962
	
963
	stopreanimate=function()
964
		if c then
965
			c=nil
966
			return true
967
		else
968
			return false
969
		end
970
	end
971
	
972
	local legcfR=cf(1,-1,0)
973
	local legcfL=cf(-1,-1,0)
974
	local raydir=v3_010*-2
975
	local function raycastlegs() --this returns 2 values: right leg raycast offset, left leg raycast offset
976
		local rY=ws:Raycast((cfr*legcfR).Position,raydir,raycastparams)
977
		local lY=ws:Raycast((cfr*legcfL).Position,raydir,raycastparams)
978
		return rY and (rY.Position.Y-(pos.Y-3)) or 0,lY and (lY.Position.Y-(pos.Y-3)) or 0
979
	end
980
981
	local function velbycfrvec() --this returns 2 values: forward/backwards movement (from -1 to 1), right/left movement (from -1 to 1)
982
		local fw=cfr.LookVector*xzvel/walkSpeed
983
		local rt=cfr.RightVector*xzvel/walkSpeed
984
		return fw.X+fw.Z,rt.X+rt.Z
985
	end
986
987
	local lastvel=v3_0
988
	local velchg1=v3_0
989
	local function velchgbycfrvec() --this returns 2 values: forward/backwards velocity change, right/left velocity change
990
		velchg1=velchg1+(lastvel-xzvel) --i recommend setting velchg1 to v3_0 when u start using this function or it will look worse
991
		lastvel=xzvel
992
		velchg1=velchg1:Lerp(v3_0,deltaTime/2)
993
		local fw=cfr.LookVector*velchg1/32
994
		local rt=cfr.RightVector*velchg1/32
995
		return fw.X+fw.Z,rt.X+rt.Z
996
	end
997
998
	local function rotToMouse(alpha) --this rotates ur character towards your mouse hit position
999
		local mpos=mouse.Hit.Position
1000
		cfr=cfr:Lerp(cf(pos,v3(mpos.X,pos.Y,mpos.Z)),alpha or deltaTime)
1001
	end
1002
1003
	local function setWalkSpeed(n)
1004
		if type(n) ~= "number" then
1005
			n=16
1006
		end
1007
		walkSpeed=n
1008
	end
1009
	local function setJumpPower(n)
1010
		if type(n) ~= "number" then
1011
			n=50
1012
		end
1013
		jumpPower=n
1014
	end
1015
	local function setGravity(n)
1016
		if type(n) ~= "number" then
1017
			n=196.2
1018
		end
1019
		gravity=n
1020
	end
1021
1022
	return {
1023
		cframes=cframes,
1024
		joints=joints,
1025
		refreshjoints=refreshjoints,
1026
		raycastlegs=raycastlegs,
1027
		velbycfrvec=velbycfrvec,
1028
		velchgbycfrvec=velchgbycfrvec,
1029
		addmode=addmode,
1030
		getPart=getPart,
1031
		getPartFromMesh=getPartFromMesh,
1032
		getJoint=getJoint,
1033
		getPartJoint=getPartJoint,
1034
		rotToMouse=rotToMouse,
1035
		setWalkSpeed=setWalkSpeed,
1036
		setJumpPower=setJumpPower,
1037
		setGravity=setGravity
1038
	}
1039
end
1040
1041
local t=reanimate()
1042
if type(t)~="table" then return end
1043
local raycastlegs=t.raycastlegs
1044
local velbycfrvec=t.velbycfrvec
1045
local velchgbycfrvec=t.velchgbycfrvec
1046
local addmode=t.addmode
1047
local getJoint=t.getJoint
1048
local RootJoint=getJoint("RootJoint")
1049
local RightShoulder=getJoint("Right Shoulder")
1050
local LeftShoulder=getJoint("Left Shoulder")
1051
local RightHip=getJoint("Right Hip")
1052
local LeftHip=getJoint("Left Hip")
1053
local Neck=getJoint("Neck")
1054
addmode("default", {
1055
idle = function()
1056
local rY, lY = raycastlegs()
1057
local Cfw, Crt = velchgbycfrvec()
1058
LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1,0)*angles(-0.15707963267948966+0.15707963267948966*sin(sine*1),-1.5707963267948966,0),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(0,0,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  Neck.C0=Neck.C0:Lerp(cf(0,1,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)    RightHip.C0=RightHip.C0:Lerp(cf(1,-1,0)*angles(0,1.5707963267948966,0),deltaTime)  RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0,0)*angles(0.3490658503988659+1.3962634015954636*sin(sine*1),1.3962634015954636,0),deltaTime)  LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,0.5,0)*angles(0.3490658503988659+1.3962634015954636*sin(sine*1),-1.3962634015954636,0),deltaTime)    
1059-
LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,1+0.4*sin(sine*1),0)*angles(-0.15707963267948966+0.06981317007977318*sin((sine+9)*40),-1.5707963267948966,0),deltaTime)  LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1+0.3*sin(sine*1),0)*angles(0,-0.15707963267948966,0),deltaTime)    RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.2,0)*angles(-1.5707963267948966+0.15707963267948966*sin((sine+2)*1),1.5707963267948966,0),deltaTime)  RightHip.C0=RightHip.C0:Lerp(cf(1,-1+0.3*sin(sine*1),0)*angles(-1.5707963267948966,1.5707963267948966,0),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(5+4*sin((sine + 0.3)*0.2),4,0)*angles(0.03490658503988659,0,3.141592653589793),deltaTime)   
1059+
1060
1061
walk = function()
1062
local Vfw, Vrt = velbycfrvec()
1063
local rY, lY = raycastlegs()
1064
local Cfw, Crt = velchgbycfrvec()
1065
LeftHip.C0=LeftHip.C0:Lerp(cf(-1,0.2 * sin(sine*1),0)*angles(0.3490658503988659,-1.5707963267948966,0),deltaTime)  Neck.C0=Neck.C0:Lerp(cf(0,1,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)    RootJoint.C0=RootJoint.C0:Lerp(cf(0,0,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,0.5,0)*angles(0.3490658503988659+0.13962634015954636*sin(sine*1),-1.5707963267948966+0.15707963267948966*sin(sine*1),0),deltaTime)
1066-
LeftHip.C0=LeftHip.C0:Lerp(cf(-1,0.2 * sin(sine*1),0)*angles(0.3490658503988659,-1.5707963267948966,0),deltaTime)  RightHip.C0=RightHip.C0:Lerp(cf(1,-1,0)*angles(-0.3490658503988659,1.5707963267948966,0),deltaTime)  LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1.5,0,0)*angles(-0.20943951023931956+0.15707963267948966*sin(sine*1),0,0),deltaTime)  RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.9+0.8*sin(sine*1),0)*angles(-0.20943951023931956+0.08726646259971647*sin(sine*1),1.5707963267948966,0),deltaTime)     Neck.C0=Neck.C0:Lerp(cf(0,1,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(2+3*sin((sine + 2)*0.2),2+0.7*sin((sine + 4)*1),0)*angles(3.490658503988659,0,3.141592653589793),deltaTime) 
1066+
RightHip.C0=RightHip.C0:Lerp(cf(1,-1,0)*angles(-0.6981317007977318-0.5235987755982988*sin(sine*1),1.7453292519943295,0),deltaTime)  RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.5,0)*angles(0.3490658503988659+0.13962634015954636*sin((sine+3)*1),1.5707963267948966-0.15707963267948966*sin(sine*1),0.15707963267948966),deltaTime)  LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1,0)*angles(0.6981317007977318+0.3490658503988659*sin(sine*1),-1.5707963267948966,0),deltaTime)
1067
end,
1068
		
1069
jump = function()
1070
local Cfw, Crt = velchgbycfrvec()
1071-
local Vfw, Vrt = velbycfrvec()  LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,1+0.4*sin(sine*1),0)*angles(-0.15707963267948966+0.06981317007977318*sin((sine+9)*40),-1.5707963267948966,0),deltaTime)  LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1+0.3*sin(sine*1),0)*angles(0,-0.15707963267948966,0),deltaTime)   RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.2,0)*angles(-1.5707963267948966+0.15707963267948966*sin((sine+2)*1),1.5707963267948966,0),deltaTime)   Neck.C0=Neck.C0:Lerp(cf(0,1,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  RightHip.C0=RightHip.C0:Lerp(cf(1,-1+0.3*sin(sine*1),0)*angles(-1.5707963267948966,1.5707963267948966,0),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(5+4*sin((sine + 0.3)*0.2),4,0)*angles(0.03490658503988659,0,3.141592653589793),deltaTime)  
1071+
local Vfw, Vrt = velbycfrvec()  RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.5,0)*angles(2.6179938779914944+0.6981317007977318*sin(sine*1),1.5847589608108512+0.3490658503988659*sin(sine*1),0),deltaTime)  Neck.C0=Neck.C0:Lerp(cf(0,1,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,0.5,0)*angles(2.6179938779914944+1.5707963267948966*sin(sine*1),-1.5707963267948966,0),deltaTime)  RightHip.C0=RightHip.C0:Lerp(cf(1,-1,0)*angles(-0.5235987755982988+0.3490658503988659*sin(sine*1),1.5707963267948966,0),deltaTime)  LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1,0)*angles(-0.8726646259971648+0.3490658503988659*sin(sine*1),-1.5707963267948966,0),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(0,0,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  
1072
end,
1073
1074
fall = function()
1075
local Vfw, Vrt = velbycfrvec()
1076
local Cfw, Crt = velchgbycfrvec()
1077-
LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,1+0.4*sin(sine*1),0)*angles(-0.15707963267948966+0.06981317007977318*sin((sine+9)*40),-1.5707963267948966,0),deltaTime)  LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1+0.3*sin(sine*1),0)*angles(0,-0.15707963267948966,0),deltaTime)  RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.2,0)*angles(-1.5707963267948966+0.15707963267948966*sin((sine+2)*1),1.5707963267948966,0),deltaTime)    RightHip.C0=RightHip.C0:Lerp(cf(1,-1+0.3*sin(sine*1),0)*angles(-1.5707963267948966,1.5707963267948966,0),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(5+4*sin((sine + 0.3)*0.2),4,0)*angles(0.03490658503988659,0,3.141592653589793),deltaTime)  
1077+
1078
RightShoulder.C0=RightShoulder.C0:Lerp(cf(1,0.5,0)*angles(2.6179938779914944+0.6981317007977318*sin(sine*1),1.5847589608108512+0.3490658503988659*sin(sine*1),0),deltaTime)  Neck.C0=Neck.C0:Lerp(cf(0,1,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)  LeftShoulder.C0=LeftShoulder.C0:Lerp(cf(-1,0.5,0)*angles(2.6179938779914944+1.5707963267948966*sin(sine*1),-1.5707963267948966,0),deltaTime)  RightHip.C0=RightHip.C0:Lerp(cf(1,-1,0)*angles(-0.5235987755982988+0.3490658503988659*sin(sine*1),1.5707963267948966,0),deltaTime)  LeftHip.C0=LeftHip.C0:Lerp(cf(-1,-1,0)*angles(-0.8726646259971648+0.3490658503988659*sin(sine*1),-1.5707963267948966,0),deltaTime)  RootJoint.C0=RootJoint.C0:Lerp(cf(0,0,0)*angles(-1.5707963267948966,0,3.141592653589793),deltaTime)
1079-
})
1079+
1080-
1080+
})