Advertisement
HenloMyDude

Virtual Reality

Nov 24th, 2019
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.12 KB | None | 0 0
  1.  
  2. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  3. local Player = owner
  4. local Mouse = owner
  5. local mouse = owner
  6. local UserInputService = owner
  7. local ContextActionService = owner
  8. local RealPlayer = Player
  9. do print("FE Compatibility code by Mokiros")local a=RealPlayer;script.Parent=a.Character;local b=Instance.new("RemoteEvent")b.Name="UserInput_Event"local function c()local d={_fakeEvent=true,Functions={},Connect=function(self,e)table.insert(self.Functions,e)end}d.connect=d.Connect;return d end;local f={Target=nil,Hit=CFrame.new(),KeyUp=c(),KeyDown=c(),Button1Up=c(),Button1Down=c(),Button2Up=c(),Button2Down=c()}local g={InputBegan=c(),InputEnded=c()}local CAS={Actions={},BindAction=function(self,h,i,j,...)CAS.Actions[h]=i and{Name=h,Function=i,Keys={...}}or nil end}CAS.UnbindAction=CAS.BindAction;local function k(self,l,...)local d=f[l]if d and d._fakeEvent then for m,e in pairs(d.Functions)do e(...)end end end;f.TrigEvent=k;g.TrigEvent=k;b.OnServerEvent:Connect(function(n,o)if n~=a then return end;f.Target=o.Target;f.Hit=o.Hit;if not o.isMouse then local p=o.UserInputState==Enum.UserInputState.Begin;if o.UserInputType==Enum.UserInputType.MouseButton1 then return f:TrigEvent(p and"Button1Down"or"Button1Up")end;if o.UserInputType==Enum.UserInputType.MouseButton2 then return f:TrigEvent(p and"Button2Down"or"Button2Up")end;for m,d in pairs(CAS.Actions)do for m,q in pairs(d.Keys)do if q==o.KeyCode then d.Function(d.Name,o.UserInputState,o)end end end;f:TrigEvent(p and"KeyDown"or"KeyUp",o.KeyCode.Name:lower())g:TrigEvent(p and"InputBegan"or"InputEnded",o,false)end end)b.Parent=NLS([==[local a=game:GetService("Players").LocalPlayer;local b=script:WaitForChild("UserInput_Event")local c=a:GetMouse()local d=game:GetService("UserInputService")local e=function(f,g)if g then return end;b:FireServer({KeyCode=f.KeyCode,UserInputType=f.UserInputType,UserInputState=f.UserInputState,Hit=c.Hit,Target=c.Target})end;d.InputBegan:Connect(e)d.InputEnded:Connect(e)local h,i;while wait(1/30)do if h~=c.Hit or i~=c.Target then h,i=c.Hit,c.Target;b:FireServer({isMouse=true,Target=i,Hit=h})end end]==],Player.Character)local r=game;local s={__index=function(self,q)local t=rawget(self,"_RealService")if t then return typeof(t[q])=="function"and function(m,...)return t[q](t,...)end or t[q]end end,__newindex=function(self,q,u)local t=rawget(self,"_RealService")if t then t[q]=u end end}local function v(d,w)d._RealService=typeof(w)=="string"and r:GetService(w)or w;return setmetatable(d,s)end;local x={GetService=function(self,t)return rawget(self,t)or r:GetService(t)end,Players=v({LocalPlayer=v({GetMouse=function(self)return f end},Player)},"Players"),UserInputService=v(g,"UserInputService"),ContextActionService=v(CAS,"ContextActionService"),RunService=v({_btrs={},RenderStepped=r:GetService("RunService").Heartbeat,BindToRenderStep=function(self,h,m,i)self._btrs[h]=self.Heartbeat:Connect(i)end,UnbindFromRenderStep=function(self,h)self._btrs[h]:Disconnect()end},"RunService")}rawset(x.Players,"localPlayer",x.Players.LocalPlayer)x.service=x.GetService;v(x,game)game,owner=x,x.Players.LocalPlayer end
  10.  
  11. msh = Instance.new("SpecialMesh",nil)
  12. msh.MeshId = "rbxassetid://1532314169"
  13. msh.TextureId = "rbxassetid://1532316153"
  14. msh.Scale = Vector3.new(0.02, 0.02, 0.02)
  15.  
  16. plr = owner
  17. char = plr.Character
  18. ra = char["Right Arm"]
  19. la = char["Left Arm"]
  20. rl = char["Right Leg"]
  21. ll = char["Left Leg"]
  22. root = char.HumanoidRootPart
  23. hed = char.Head
  24. tors = char.Torso
  25. hum = char.Humanoid
  26.  
  27. function ezweld(p, a, b, cf)
  28. local weld = Instance.new("Weld",p)
  29. weld.Part0 = a
  30. weld.Part1 = b
  31. weld.C0 = cf
  32. return weld
  33. end
  34.  
  35. function Swait(number)
  36. if number == 0 or number == nil then
  37. game:GetService("RunService").Heartbeat:Wait()
  38. else
  39. for i = 1,number do
  40. game:GetService("RunService").Heartbeat:Wait()
  41. end
  42. end
  43. end
  44.  
  45. clerp = function(toclerp, cf, number)
  46. local joint = toclerp
  47. joint.C0 = joint.C0:Lerp(cf, number)
  48. end
  49.  
  50. clerp2 = function(toclerp, cf)
  51. local joint = toclerp
  52. joint.C0 = cf
  53. end
  54.  
  55. clerp3 = function(toclerp, cf, number)
  56. local joint = toclerp
  57. joint.C1 = joint.C1:Lerp(cf, number)
  58. end
  59.  
  60. anim = "Idle"
  61. attack = false
  62. local RS = char.Torso["Right Shoulder"]
  63. local LS = char.Torso["Left Shoulder"]
  64. local RH = char.Torso["Right Hip"]
  65. local LH = char.Torso["Left Hip"]
  66. local neck = char.Torso["Neck"]
  67. local anim = "Idle"
  68. local root = char.HumanoidRootPart
  69. local rootj = root.RootJoint
  70. local timepos = 0
  71. local sine = 0
  72. local RSnor = RS.C0
  73. local LSnor = LS.C0
  74. local RHnor = RH.C0
  75. local LHnor = LH.C0
  76. local RSnor2 = RS.C1
  77. local LSnor2 = LS.C1
  78. local RHnor2 = RH.C1
  79. local LHnor2 = LH.C1
  80. local rootjnor = rootj.C0
  81. local necknor = neck.C0
  82. local tors = char.Torso
  83. local playstealanim = false
  84. hold = false
  85. mouse = plr:GetMouse()
  86. hold = false
  87. Debris = game:GetService("Debris")
  88.  
  89. IT = Instance.new
  90. Rad = math.rad
  91. Cos = math.cos
  92. Sin = math.sin
  93. BrickC = BrickColor.new
  94. C3 = Color3.new
  95. VT = Vector3.new
  96.  
  97. function addcontroller(part)
  98. local control1 = Instance.new("Part",char)
  99. control1.CanCollide = false
  100. control1.Anchored = false
  101. control1.Name = "controller"
  102. control1.Size = Vector3.new(0.1, 0.1, 0.1)
  103. local mesh1 = msh:Clone()
  104. mesh1.Parent = control1
  105. local weld1 = ezweld(char, part, control1, CFrame.new(0, -part.Size.y / 2.45, -0.15) * CFrame.Angles(Rad(-90), 0, 0))
  106. return control1
  107. end
  108.  
  109. local control1 = addcontroller(ra)
  110. local control2 = addcontroller(la)
  111.  
  112. --hed is Head
  113. --tors is Torso
  114. --la is Left Arm
  115. --HEADLERP is already added for u
  116.  
  117. local HEADLERP = Instance.new("ManualWeld")
  118. HEADLERP.Parent = hed
  119. HEADLERP.Part0 = hed
  120. HEADLERP.Part1 = hed
  121. HEADLERP.C0 = CFrame.new(0, -1.5, -0) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
  122.  
  123. MseGuide = true
  124. OrgnC0 = neck.C0
  125. local movelimbs = coroutine.wrap(function()
  126. while game:GetService("RunService").RenderStepped:wait() do
  127. TrsoLV = tors.CFrame.lookVector
  128. Dist = nil
  129. Diff = nil
  130. if not MseGuide then
  131. print("Failed to recognize")
  132. else
  133. local _, Point = workspace:FindPartOnRay(Ray.new(hed.CFrame.p, mouse.Hit.lookVector), workspace, false, true)
  134. Dist = (hed.CFrame.p-Point).magnitude
  135. Diff = hed.CFrame.Y-Point.Y
  136. local _, Point2 = workspace:FindPartOnRay(Ray.new(la.CFrame.p, mouse.Hit.lookVector), workspace, false, true)
  137. Dist2 = (la.CFrame.p-Point).magnitude
  138. Diff2 = la.CFrame.Y-Point.Y
  139. HEADLERP.C0 = CFrame.new(0, -1.5, -0) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0))
  140. neck.C0 = OrgnC0*CFrame.Angles((math.tan(Diff/Dist)*1.5), 0, (((hed.CFrame.p-Point).Unit):Cross(tors.CFrame.lookVector)).Y*1.5)
  141. end
  142. end
  143. end)
  144.  
  145. movelimbs()
  146.  
  147. NLS([[
  148.  
  149. function Swait(number)
  150. if number == 0 or number == nil then
  151. game:GetService("RunService").Heartbeat:Wait()
  152. else
  153. for i = 1,number do
  154. game:GetService("RunService").Heartbeat:Wait()
  155. end
  156. end
  157. end
  158.  
  159. while true do
  160. Swait()
  161. for i,v in pairs (owner.Character:GetChildren()) do
  162. if v:IsA("Part") and v.Name == "controller" then
  163. v.LocalTransparencyModifier = 0
  164. end
  165. end
  166. owner.Character["Right Arm"].LocalTransparencyModifier = 0
  167. owner.Character["Left Arm"].LocalTransparencyModifier = 0
  168. owner.Character["Right Leg"].LocalTransparencyModifier = 0
  169. owner.Character["Left Leg"].LocalTransparencyModifier = 0
  170. owner.Character["Torso"].LocalTransparencyModifier = 0
  171. end
  172.  
  173. ]],char)
  174.  
  175. Grabbing = false
  176. local CameraCFrame = CFrame.new(0, 0, 0)
  177. local PushGrabbingPart = true
  178.  
  179. local CamCFrame = Instance.new("RemoteEvent",char)
  180. CamCFrame.Name = "CamCFrame"
  181.  
  182. NLS([[
  183.  
  184. plr = owner
  185. char = plr.Character
  186. RootPart = char.HumanoidRootPart
  187. cam = workspace.CurrentCamera
  188. mu = plr:GetMouse()
  189.  
  190. while true do
  191. game:GetService("RunService").stepped:wait()
  192. char.CamCFrame:FireServer(cam.CFrame)
  193. RootPart.CFrame = CFrame.new(RootPart.Position,Vector3.new(mu.Hit.p.X,RootPart.Position.Y,mu.Hit.p.Z))
  194. end
  195.  
  196. ]],char)
  197.  
  198. CamCFrame.OnServerEvent:Connect(function(_,CAMCF)
  199. CameraCFrame = CAMCF
  200. end)
  201.  
  202. function nograv(PART)
  203. local bodyForced = Instance.new('BodyForce', PART)
  204. bodyForced.Name = 'ANTGR'
  205. bodyForced.Force = Vector3.new(0, PART:GetMass() * game.Workspace.Gravity, 0)
  206. return bodyForced
  207. end
  208.  
  209. Range = 5
  210.  
  211. function CreatePart(PARENT, MATERIAL, REFLECTANCE, TRANSPARENCY, BRICKCOLOR, NAME, SIZE, ANCHOR)
  212. local NEWPART = Instance.new("Part",PARENT)
  213. NEWPART.Reflectance = REFLECTANCE
  214. NEWPART.Transparency = TRANSPARENCY
  215. NEWPART.CanCollide = false
  216. NEWPART.Locked = true
  217. if ANCHOR == true then
  218. NEWPART.Anchored = true
  219. end
  220. NEWPART.BrickColor = BrickColor.new(BRICKCOLOR)
  221. NEWPART.Name = NAME
  222. NEWPART.Size = SIZE
  223. NEWPART.Position = tors.Position
  224. NEWPART.Material = MATERIAL
  225. return NEWPART
  226. end
  227.  
  228. local function weldBetween(a, b)
  229. local weldd = Instance.new("ManualWeld")
  230. weldd.Part0 = a
  231. weldd.Part1 = b
  232. weldd.C0 = CFrame.new()
  233. weldd.C1 = b.CFrame:inverse() * a.CFrame
  234. weldd.Parent = a
  235. return weldd
  236. end
  237.  
  238. function spawnsword(cf)
  239. local sword = Instance.new("Part",workspace)
  240. sword.Size = Vector3.new(1, 0.8, 4)
  241. sword.CFrame = cf
  242. sword.Anchored = false
  243. sword.Touched:connect(function(hit)
  244. for i,v in pairs (hit.Parent:children()) do
  245. if v:IsA("Humanoid") and v.Parent ~= char then
  246. v.Health = v.Health - 5
  247. end
  248. end
  249. end)
  250. local mesh = Instance.new("SpecialMesh",sword)
  251. mesh.MeshId = "rbxasset://fonts/sword.mesh"
  252. mesh.TextureId = "rbxasset://textures/SwordTexture.png"
  253. return sword
  254. end
  255.  
  256. function spawnsponge(cf)
  257. local sponge = Instance.new("Part",workspace)
  258. sponge.Size = Vector3.new(2.5, 1.125, 4.25)
  259. sponge.CFrame = cf
  260. sponge.Anchored = false
  261. sponge.Touched:connect(function(hit)
  262. for i,v in pairs (hit:children()) do
  263. if v:IsA("Decal") and not v:FindFirstChild("cantclean") then
  264. v.Transparency = v.Transparency + 0.05
  265. local cantclean = Instance.new("NumberValue",v)
  266. cantclean.Name = "cantclean"
  267. Debris:AddItem(cantclean, 0.25)
  268. end
  269. end
  270. end)
  271. local mesh = Instance.new("SpecialMesh",sponge)
  272. mesh.MeshId = "rbxassetid://551373055"
  273. mesh.TextureId = "rbxassetid://551373057"
  274. mesh.Scale = Vector3.new(0.1, 0.1, 0.1)
  275. return sponge
  276. end
  277.  
  278. function toasted(cf)
  279. local a = 0.0025
  280. local bread = Instance.new("Part",workspace) bread.CanCollide = true bread.Anchored = false bread.CFrame = cf bread.Size = Vector3.new(1.045, 1.015, 0.101) bread.Orientation = Vector3.new(90, 180, 0)
  281. local bmesh = Instance.new("SpecialMesh",bread) bmesh.MeshType = "FileMesh" bmesh.MeshId = "rbxassetid://1614924885" bmesh.TextureId = "rbxassetid://1614940093" bmesh.Scale = Vector3.new(a, a, a)
  282. return bread
  283. end
  284.  
  285. function grab(Tag)
  286. local GrabbingBall = CreatePart(char,"Neon",0,1,"White","GrabbingBall",VT(0.1,0.1,0.1),false)
  287. GrabbingBall.Shape = "Ball"
  288. local xs,ys,zs = CameraCFrame:ToEulerAnglesXYZ()
  289. local starterrot = CFrame.new(0,0,0) * CFrame.Angles(Rad(math.deg(xs)),Rad(math.deg(ys)),Rad(math.deg(zs)))
  290. local TagMass = Tag.Massless
  291. local OldVelocity = Tag.Velocity
  292. Tag.Velocity = VT(0,0,0)
  293. Tag.Massless = false
  294. local AntiGrav = nograv(Tag)
  295. GrabbingBall.CFrame = CFrame.new(mouse.Hit.p,hed.Position)
  296. weldBetween(GrabbingBall,Tag)
  297. nograv(GrabbingBall)
  298. repeat
  299. Swait()
  300. if Grabbing == true then
  301. GrabbingBall.Velocity = VT(0,0,0)
  302. Tag.Velocity = VT(0,0,0)
  303. GrabbingBall.RotVelocity = VT(0,0,0)
  304. Tag.RotVelocity = VT(0,0,0)
  305. local NewPos = CameraCFrame.lookVector * Range
  306. NewPos = hed.Position + NewPos
  307. GrabbingBall.CFrame = CFrame.new(NewPos,hed.Position)
  308. if Tag.Name == "shov" then
  309. game.Workspace.Terrain:FillBall(Tag.Base.Position,3.5,"Air")
  310. end
  311. if Tag.Name == "Furniture" then
  312. Tag.Anchored = false
  313. end
  314. end
  315. until Grabbing == false or PushGrabbingPart == true
  316. GrabbingBall:Destroy()
  317. AntiGrav:Destroy()
  318. Tag.Velocity = OldVelocity
  319. Tag.Massless = TagMass
  320. if PushGrabbingPart == true then
  321. Tag.Velocity = CameraCFrame.lookVector * 100
  322. PushGrabbingPart = false
  323. end
  324. end
  325.  
  326. mouse.Button2Down:Connect(function()
  327. if mouse.Target then
  328. if mouse.Target.Name ~= "Base" then
  329. if (mouse.Target.Position - hed.Position).Magnitude < 15 then
  330. Grabbing = true
  331. grab(mouse.Target)
  332. end
  333. end
  334. end
  335. end)
  336.  
  337. mouse.Button2Up:Connect(function()
  338. if Grabbing == true then
  339. Grabbing = false
  340. Range = 5
  341. end
  342. end)
  343.  
  344. mouse.KeyDown:connect(function(key)
  345. if key == "e" then
  346. spawnsword(tors.CFrame)
  347. end
  348. if key == "t" then
  349. toasted(tors.CFrame)
  350. end
  351. if key == "r" then
  352. spawnsponge(tors.CFrame)
  353. end
  354. end)
  355.  
  356. mouse.Button1Down:connect(function()
  357. PushGrabbingPart = true
  358. end)
  359.  
  360. local wld1 = ezweld(char, tors, ra, RS.C0)
  361. wld1.C1 = RS.C1
  362.  
  363. local wld2 = ezweld(char, tors, la, LS.C0)
  364. wld2.C1 = LS.C1
  365.  
  366. while true do
  367. Swait()
  368. tframe = char.Torso.CFrame
  369. taim = mouse.Hit.p -( tframe.p )
  370. wld1.C0 = CFrame.Angles(Rad(90), 0, 0) * (CFrame.new(Vector3.new(),tframe:vectorToObjectSpace(taim))*CFrame.Angles(0,math.pi/2,0))+Vector3.new( 1, 0.5, 0 ),1
  371. wld2.C0 = CFrame.Angles(Rad(90), 0, 0) * (CFrame.new(Vector3.new(),tframe:vectorToObjectSpace(taim))*CFrame.Angles(0,-math.pi/2,0))+Vector3.new( -1, 0.5, 0 ),1
  372. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement