Advertisement
IHATEMICROWAVEOVEN

pa no-attack-latency demonstration

Jan 3rd, 2024
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.16 KB | None | 0 0
  1. A followup to my original code. Below, I have listed what to do with the following scripts:
  2. game > ServerScriptService > Stats
  3. game > StarterGui > SkillsGui > WeaponsController
  4.  
  5. Additionally, PLEASE REMEMBER:
  6. MAKE A REMOTEEVENT PARENTED TO REPLICATEDSTORAGE AND NAME IT "WeaponStatsEvent"
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. Below shows what to insert for game > ServerScriptService > Stats.
  20.  
  21.  
  22.  
  23.  
  24. local DataStoreManager = require(script:WaitForChild("DataStore"))
  25. local StarterData = require(script:WaitForChild("StarterData"))
  26. local PlayerUpdateData = require(script:WaitForChild("PlayerUpdateData"))
  27. local OldLoading = require(script:WaitForChild("OldLoading"))
  28. local DefaultData = {}
  29. for key, value in pairs(StarterData.StarterData) do
  30. DefaultData[key] = value.DefaultValue
  31. end
  32. local PlayerDataStore = DataStoreManager.new("DataStore_PlayerData", DefaultData)
  33. local DataHolder = Instance.new("Folder", game:GetService("ReplicatedStorage"))
  34. DataHolder.Name = "DataHolder"
  35. local PlayerData = {}
  36. -- NEW STUFF
  37. -- NEW STUFF
  38. -- NEW STUFF
  39. -- NEW STUFF
  40. -- NEW STUFF
  41. -- NEW STUFF
  42. -- NEW STUFF
  43. -- NEW STUFF
  44. -- Copy the below line and paste it into the Stats script in a similar position.
  45. local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
  46. -- END OF NEW STUFF
  47. -- END OF NEW STUFF
  48. -- END OF NEW STUFF
  49. -- END OF NEW STUFF
  50. -- END OF NEW STUFF
  51. -- END OF NEW STUFF
  52. -- END OF NEW STUFF
  53. function GetTypeFromVar(Var)
  54. if type(Var) == "number" then return "NumberValue"
  55. elseif type(Var) == "string" then return "StringValue"
  56. elseif type(Var) == "boolean" then return "BoolValue" end
  57. end
  58. function RegenerateData(Data, key, value)
  59. if key ~= nil and value ~= nil then
  60. local UserDataHolder = DataHolder:FindFirstChild(Data.userId)
  61. if UserDataHolder ~= nil then
  62. if UserDataHolder:FindFirstChild(key) then
  63. if UserDataHolder[key].ClassName == GetTypeFromVar(value) then
  64. UserDataHolder[key].Value = value
  65. else
  66. UserDataHolder:Destroy()
  67. local d = Instance.new(GetTypeFromVar(value), UserDataHolder)
  68. d.Name = key
  69. d.Value = value
  70. end
  71. else
  72. local d = Instance.new(GetTypeFromVar(value), UserDataHolder)
  73. d.Name = key
  74. d.Value = value
  75. end
  76. else
  77. RegenerateData(Data)
  78. end
  79. else
  80. if DataHolder:FindFirstChild(Data.userId) then DataHolder[Data.userId]:Destroy() end
  81. local UserDataHolder = Instance.new("Folder", DataHolder)
  82. UserDataHolder.Name = tostring(Data.userId)
  83. for k, v in pairs(Data.dataSet) do
  84. local d = Instance.new(GetTypeFromVar(v), UserDataHolder)
  85. d.Name = k
  86. d.Value = v
  87. end
  88. end
  89. end
  90. local Events = {}
  91. function PlayerAdded(Player)
  92. local SaveData = PlayerDataStore:GetSaveData(Player)
  93. for key, value in pairs(StarterData.StarterData) do
  94. if SaveData:Get(key) == nil or value.Permament == false then
  95. SaveData:Set(key, value.DefaultValue)
  96. end
  97. end
  98. RegenerateData(SaveData)
  99. Events[Player.UserId] = {}
  100. Events[Player.UserId]["RegenData"] = SaveData.regendata.Event:Connect(function() RegenerateData(SaveData) end)
  101. Events[Player.UserId]["OnUpdate"] = SaveData.onupdate.Event:Connect(function(...) RegenerateData(SaveData, ...) end)
  102. Player.CharacterAdded:Connect(function(Character)
  103. for key, value in pairs(StarterData.ResetOnSpawn) do
  104. SaveData:Set(key, value)
  105. end
  106. end)
  107. PlayerData[Player.UserId] = SaveData
  108. OldLoading(Player, SaveData)
  109. spawn(function() PlayerUpdateData(Player, SaveData) end)
  110. end
  111. function PlayerRemoving(Player)
  112. PlayerData[Player.UserId] = nil
  113. Events[Player.UserId]["RegenData"]:Disconnect()
  114. Events[Player.UserId]["OnUpdate"]:Disconnect()
  115. Events[Player.UserId] = nil
  116. local UserDataHolder = DataHolder:FindFirstChild(Player.UserId)
  117. if UserDataHolder ~= nil then
  118. UserDataHolder:Destroy()
  119. end
  120. end
  121. game:GetService("Players").PlayerAdded:Connect(PlayerAdded)
  122. game:GetService("Players").PlayerRemoving:Connect(PlayerRemoving)
  123. for _, Player in pairs(game:GetService("Players"):GetPlayers()) do PlayerAdded(Player) end
  124. return {
  125. GetStat = function(Player, ...)
  126. pcall(function() Player = Player.UserId end)
  127. if type(Player) ~= "number" then warn("You should provide id or player instance to get data!") return nil end
  128. local Stats = {...}
  129. if #Stats == 0 then warn("You should provide at least one stat!") return nil end
  130. if PlayerData[Player] then
  131. local Return = {}
  132. for i = 1, #Stats, 1 do
  133. table.insert(Return, PlayerData[Player]:Get(Stats[i]))
  134. end
  135. return unpack(Return)
  136. end
  137. return nil
  138. end;
  139. SetStat = function(Player, ...)
  140. -- NEW STUFF
  141. -- NEW STUFF
  142. -- NEW STUFF
  143. -- NEW STUFF
  144. -- NEW STUFF
  145. -- NEW STUFF
  146. -- NEW STUFF
  147. -- NEW STUFF
  148. -- Copy the below line and paste it into the Stats script in a similar position.
  149. local PlayerObject = Player
  150. -- END OF NEW STUFF
  151. -- END OF NEW STUFF
  152. -- END OF NEW STUFF
  153. -- END OF NEW STUFF
  154. -- END OF NEW STUFF
  155. -- END OF NEW STUFF
  156. -- END OF NEW STUFF
  157. pcall(function() Player = Player.UserId end)
  158. if type(Player) ~= "number" then warn("You should provide id or player instance to get data!") return nil end
  159. local Stats = {...}
  160. if #Stats == 0 or #Stats % 2 == 1 then warn("You should provide two or two's multiplier arguments!") return nil end
  161. if PlayerData[Player] then
  162. for i = 1, #Stats, 2 do
  163. PlayerData[Player]:Set(Stats[i], Stats[i+1])
  164. -- NEW STUFF
  165. -- NEW STUFF
  166. -- NEW STUFF
  167. -- NEW STUFF
  168. -- NEW STUFF
  169. -- NEW STUFF
  170. -- NEW STUFF
  171. -- NEW STUFF
  172. -- Copy the below line and paste it into the Stats script in a similar position.
  173. if Stats[i]=="SLP" or Stats[i]=="PvP" then weaponsEvent:FireClient(PlayerObject, Stats[i], Stats[i+1]) end
  174. -- END OF NEW STUFF
  175. -- END OF NEW STUFF
  176. -- END OF NEW STUFF
  177. -- END OF NEW STUFF
  178. -- END OF NEW STUFF
  179. -- END OF NEW STUFF
  180. -- END OF NEW STUFF
  181. end
  182. end
  183. return nil
  184. end;
  185. PlayerDataStore = PlayerDataStore;
  186. StarterData = DefaultData;
  187. }
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218. Below shows what to insert for game > StarterGui > SkillsGui > WeaponsController.
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. game.ReplicatedStorage:WaitForChild("WEAPONFUNCTION")
  226.  
  227. function CallWeaponServer(...)
  228. return game.ReplicatedStorage.WEAPONFUNCTION:InvokeServer(...)
  229. end
  230.  
  231. game.ReplicatedStorage:WaitForChild("FUNCTION")
  232.  
  233. function CallServer(...)
  234. return game.ReplicatedStorage.FUNCTION:InvokeServer(...)
  235. end
  236.  
  237. -- NEW STUFF
  238. -- NEW STUFF
  239. -- NEW STUFF
  240. -- NEW STUFF
  241. -- NEW STUFF
  242. -- NEW STUFF
  243. -- NEW STUFF
  244. -- NEW STUFF
  245. -- Copy the below line and paste it into the WeaponsController script in a similar position.
  246. local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
  247. -- END OF NEW STUFF
  248. -- END OF NEW STUFF
  249. -- END OF NEW STUFF
  250. -- END OF NEW STUFF
  251. -- END OF NEW STUFF
  252. -- END OF NEW STUFF
  253. -- END OF NEW STUFF
  254.  
  255. local DeviceType = nil
  256. local selectedweapon = nil
  257. local weapons = {}
  258.  
  259. local gui = script.Parent
  260.  
  261. function Weap(t, id)
  262. if t == "E" then
  263. gui.Holder["Skill"..tostring(id)].ReloadBar.Visible = true
  264. gui.Holder["Skill"..tostring(id)].ReloadFullBar.Visible = true
  265. gui.Holder["Skill"..tostring(id)].ReloadText.Visible = true
  266. elseif t == "UE" then
  267. gui.Holder["Skill"..tostring(id)].ReloadBar.Visible = false
  268. gui.Holder["Skill"..tostring(id)].ReloadFullBar.Visible = false
  269. gui.Holder["Skill"..tostring(id)].ReloadText.Visible = false
  270. end
  271. end
  272.  
  273. function UpdateGui()
  274. for _, i in pairs(script.CurrentClientModules:GetChildren()) do i:Destroy() end
  275. for i = 1, 4 do
  276. if weapons[i] then
  277. if script.ClientModules:FindFirstChild(weapons[i]) then
  278. script.ClientModules[weapons[i]]:Clone().Parent = script.CurrentClientModules
  279. end
  280. end
  281. local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
  282. frame.SkillName.Text = weapons[i] or " "
  283. end
  284. end
  285.  
  286. function UpdateGuiDevice()
  287. local function Check(loc)
  288. for _, i in pairs(loc:GetChildren()) do
  289. if i:IsA'Frame' then
  290. Check(i)
  291. else
  292. if i.Name == DeviceType.."HotKeys" then
  293. i.Visible = true
  294. elseif string.find(i.Name, "HotKeys") then
  295. i.Visible = false
  296. end
  297. end
  298. end
  299. end
  300. Check(gui.Holder)
  301. end
  302.  
  303. function SkillCUC(t, i)
  304. if t == "C" then
  305. local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
  306. frame.SkillName.TextColor3 = Color3.new(47/255, 187/255, 200/255)
  307. elseif t == "UC" then
  308. local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
  309. frame.SkillName.TextColor3 = Color3.new(1,1,1)
  310. end
  311. end
  312. function SetupGui()
  313. script.Parent.Holder.Visible = true
  314. for i = 1, 4 do
  315. local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
  316. frame.SkillName.Text = weapons[i] or " "
  317. frame.SkillName.MouseButton1Click:connect(function()
  318. if weapons[i] ~= nil then
  319. SelectWeapon(i)
  320. end
  321. end)
  322. end
  323. end
  324.  
  325. local debounce = {[1] = true, [2] = true, [3] = true, [4] = true}
  326. local debounceuse = true
  327. local LastUse = tick()
  328. -- NEW STUFF
  329. -- NEW STUFF
  330. -- NEW STUFF
  331. -- NEW STUFF
  332. -- NEW STUFF
  333. -- NEW STUFF
  334. -- NEW STUFF
  335. -- NEW STUFF
  336. -- Copy the below line and paste it into the WeaponsController script in a similar position.
  337. local SLPvalue = 0
  338. local PvPvalue = 0
  339. -- END OF NEW STUFF
  340. -- END OF NEW STUFF
  341. -- END OF NEW STUFF
  342. -- END OF NEW STUFF
  343. -- END OF NEW STUFF
  344. -- END OF NEW STUFF
  345. -- END OF NEW STUFF
  346.  
  347. function Use()
  348. local curweaponf = selectedweapon
  349. if debounceuse then
  350. debounceuse = false
  351. if debounce[curweaponf] then
  352.  
  353. -- These are the old lines. Delete these.
  354. --if CallServer("GetStat", "PvP") == 1 then
  355. --if CallServer("GetStat", "SLP") == 0 and CallServer("GetHumanoidHealth") ~= 0 then
  356.  
  357. -- NEW STUFF
  358. -- NEW STUFF
  359. -- NEW STUFF
  360. -- NEW STUFF
  361. -- NEW STUFF
  362. -- NEW STUFF
  363. -- NEW STUFF
  364. -- NEW STUFF
  365. -- Copy the below line and paste it into the WeaponsController script in a similar position.
  366. if PvPvalue == 1 then
  367. if SLPvalue == 0 and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
  368. -- END OF NEW STUFF
  369. -- END OF NEW STUFF
  370. -- END OF NEW STUFF
  371. -- END OF NEW STUFF
  372. -- END OF NEW STUFF
  373. -- END OF NEW STUFF
  374. -- END OF NEW STUFF
  375.  
  376. if script.CurrentClientModules:FindFirstChild(weapons[curweaponf]) then
  377. game.Players.LocalPlayer.PlayerGui.GameGui.LocalScript.WeaponUsed.Value = true
  378. debounce[curweaponf] = false
  379. local tab = require(script.CurrentClientModules[weapons[curweaponf]])
  380. local func = tab[1]
  381. local reload = tab[2]
  382. spawn(function() local returned = func(game.Players.LocalPlayer, DeviceType, CallServer, CallWeaponServer) if returned ~= nil then reload = returned end LastUse = tick() end)
  383. spawn(function()
  384. local i = 0
  385. while i < reload do
  386. if 0.8 * (i / (reload)) < 0.1 then
  387. gui.Holder["Skill"..tostring(curweaponf)].ReloadBar:TweenSize(UDim2.new(0.1, 0, -0.15, 0), "Out", "Quad", 1, true)
  388. else
  389. gui.Holder["Skill"..tostring(curweaponf)].ReloadBar:TweenSize(UDim2.new(0.8 * (i / (reload)), 0, -0.15, 0), "Out", "Quad", 1, true)
  390. end
  391. gui.Holder["Skill"..tostring(curweaponf)].ReloadText.Text = "Reloading!"
  392. i = i + wait(1/60)
  393. end
  394. gui.Holder["Skill"..tostring(curweaponf)].ReloadBar:TweenSize(UDim2.new(0.8, 0, -0.15, 0), "Out", "Quad", 1, true)
  395. gui.Holder["Skill"..tostring(curweaponf)].ReloadText.Text = "Ready!"
  396. debounce[curweaponf] = true
  397. end)
  398. SkillCUC("UC", curweaponf)
  399. selectedweapon = nil
  400. end
  401. end
  402. else
  403. game.StarterGui:SetCore("SendNotification", {
  404. Title = "Skills";
  405. Text = "Turned the PvP on!";
  406. Duration = 2;
  407. })
  408. CallServer("ChangeStat", "PvP", 1)
  409. end
  410. end
  411. wait(2)
  412. debounceuse = true
  413. end
  414. end
  415.  
  416. function SelectWeapon(num)
  417. if weapons[num] ~= nil then
  418. if selectedweapon == num then
  419. selectedweapon = nil
  420. SkillCUC("UC", num)
  421. else
  422. selectedweapon = num
  423. SkillCUC("C", num)
  424. if num ~= 1 then SkillCUC("UC", 1) end
  425. if num ~= 2 then SkillCUC("UC", 2) end
  426. if num ~= 3 then SkillCUC("UC", 3) end
  427. if num ~= 4 then SkillCUC("UC", 4) end
  428. end
  429. end
  430. end
  431. game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(i)
  432. if script.ClientModules:FindFirstChild(i.Name) then
  433. script.ClientModules[i.Name]:Clone().Parent = script.CurrentClientModules
  434. end
  435. if weapons[1] == nil then table.insert(weapons, 1, i.Name) Weap("E", 1)
  436. elseif weapons[2] == nil then table.insert(weapons, 2, i.Name) Weap("E", 2)
  437. elseif weapons[3] == nil then table.insert(weapons, 3, i.Name) Weap("E", 3)
  438. elseif weapons[4] == nil then table.insert(weapons, 4, i.Name) Weap("E", 4)
  439. end
  440. UpdateGui()
  441. end)
  442. game.Players.LocalPlayer.Backpack.ChildRemoved:connect(function(i)
  443. if script.CurrentClientModules:FindFirstChild(i.Name) then
  444. script.CurrentClientModules[i.Name]:Destroy()
  445. end
  446. if weapons[1] == i.Name then weapons[1] = nil Weap("UE", 1) if selectedweapon == 1 then selectedweapon = nil SkillCUC("UC", 1) end
  447. elseif weapons[2] == i.Name then weapons[2] = nil Weap("UE", 2) if selectedweapon == 2 then selectedweapon = nil SkillCUC("UC", 2) end
  448. elseif weapons[3] == i.Name then weapons[3] = nil Weap("UE", 3) if selectedweapon == 3 then selectedweapon = nil SkillCUC("UC", 3) end
  449. elseif weapons[4] == i.Name then weapons[4] = nil Weap("UE", 4) if selectedweapon == 4 then selectedweapon = nil SkillCUC("UC", 4) end
  450. end
  451. UpdateGui()
  452. end)
  453. repeat wait() until weapons[1] ~= nil
  454. SetupGui()
  455. local debounce = true
  456. game:GetService("UserInputService").InputBegan:connect(function(input, gp)
  457. if debounce then
  458. debounce = false
  459. if input.UserInputType == Enum.UserInputType.Gamepad1 or input.UserInputType == Enum.UserInputType.Keyboard then
  460. -- EXECUTING
  461. if input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.ButtonL1 then
  462. if weapons[1] ~= nil then
  463. SelectWeapon(1)
  464. end
  465. elseif input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.ButtonL2 then
  466. if weapons[2] ~= nil then
  467. SelectWeapon(2)
  468. end
  469. elseif input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.ButtonR2 then
  470. if weapons[3] ~= nil then
  471. SelectWeapon(3)
  472. end
  473. elseif input.KeyCode == Enum.KeyCode.T or input.KeyCode == Enum.KeyCode.ButtonR1 then
  474. if weapons[4] ~= nil then
  475. SelectWeapon(4)
  476. end
  477. elseif input.KeyCode == Enum.KeyCode.ButtonX then
  478. if selectedweapon ~= nil then
  479. Use()
  480. end
  481. end
  482. elseif input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  483. if not gp then
  484. if selectedweapon ~= nil then
  485. Use()
  486. end
  487. end
  488. end
  489. debounce = true
  490. end
  491. end)
  492.  
  493. local UIS = game:GetService("UserInputService")
  494. if UIS.GamepadEnabled then
  495. DeviceType = "Gamepad"
  496. UpdateGuiDevice()
  497. elseif UIS.MouseEnabled then
  498. DeviceType = "Pc"
  499. UpdateGuiDevice()
  500. elseif UIS.TouchEnabled then
  501. DeviceType = "Mobile"
  502. UpdateGuiDevice()
  503. end
  504. UIS.GamepadConnected:connect(function(GPN)
  505. if GPN == Enum.UserInputType.Gamepad1 then
  506. DeviceType = "Gamepad"
  507. UpdateGuiDevice()
  508. end
  509. end)
  510. UIS.GamepadDisconnected:connect(function(GPN)
  511. if GPN == Enum.UserInputType.Gamepad1 then
  512. if UIS.MouseEnabled then
  513. DeviceType = "Pc"
  514. UpdateGuiDevice()
  515. elseif UIS.TouchEnabled then
  516. DeviceType = "Mobile"
  517. UpdateGuiDevice()
  518. end
  519. end
  520. end)
  521.  
  522. spawn(function()
  523. local CurHP = CallServer("GetHP")
  524. local LastHPChange = tick()
  525. while wait(1) do
  526. local HP = CallServer("GetHP")
  527. if HP < CurHP then LastHPChange = tick() end
  528. CurHP = HP
  529. if tick() - LastUse > 6 and tick() - LastHPChange > 6 then
  530. CallServer("HealPlayer", 10)
  531. LastUse = tick()
  532. end
  533. end
  534. end)
  535.  
  536.  
  537. -- NEW STUFF
  538. -- NEW STUFF
  539. -- NEW STUFF
  540. -- NEW STUFF
  541. -- NEW STUFF
  542. -- NEW STUFF
  543. -- NEW STUFF
  544. -- NEW STUFF
  545. -- Copy the below line and paste it into the WeaponsController script in a similar position.
  546. weaponsEvent.OnClientEvent:Connect(function(...)
  547. local args = {...}
  548. --[1]: the name of a stat
  549. --[2]: the stat's new value
  550.  
  551. if args[1]=="SLP" then
  552. SLPvalue = args[2]
  553. elseif args[1]=="PvP" then
  554. PvPvalue = args[2]
  555. end
  556. end)
  557. -- END OF NEW STUFF
  558. -- END OF NEW STUFF
  559. -- END OF NEW STUFF
  560. -- END OF NEW STUFF
  561. -- END OF NEW STUFF
  562. -- END OF NEW STUFF
  563. -- END OF NEW STUFF
  564.  
  565.  
  566.  
  567.  
  568.  
  569. goo luck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement