Advertisement
IHATEMICROWAVEOVEN

pa no-attack-latency system

Dec 31st, 2023 (edited)
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. This is a system that allows you to reduce latency to near-0 in PA's attack system.
  2. Normally, the old system's lag is caused by the fact that it makes 3 calls to the server each time an attack is used.
  3. The script yields every time a call is made, since it has to get data from the server...
  4. ...however, doing this just 1 time can give you ~100 ms of latency even in a fresh and unlaggy server.
  5. The new system makes 0 calls to the server and instead updates the data dynamically.
  6. Enjoy!
  7.  
  8.  
  9.  
  10.  
  11. 1. Navigate to ReplicatedStorage. Create a RemoteEvent parented to it. Rename this RemoteEvent to "WeaponStatsEvent".
  12.  
  13.  
  14. 2. In ServerScriptService > Stats, insert this towards the top:
  15. local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
  16.  
  17.  
  18. 3. Still in ServerScriptService > Stats, scroll down to function SetStat at the bottom of the script.
  19. Right before the first line of SetStat, put this:
  20. local PlayerObject = Player
  21. Then, in the for-loop later in SetStat, put this:
  22. if Stats[i]=="SLP" or Stats[i]=="PvP" then weaponsEvent:FireClient(PlayerObject, Stats[i], Stats[i+1]) end
  23.  
  24. (SetStat should now look like this, with new additions marked:
  25. SetStat = function(Player, ...)
  26. -- START OF NEW STUFF
  27. -- START OF NEW STUFF
  28. -- START OF NEW STUFF
  29. local PlayerObject = Player
  30. -- END OF NEW STUFF
  31. -- END OF NEW STUFF
  32. -- END OF NEW STUFF
  33. pcall(function() Player = Player.UserId end)
  34. if type(Player) ~= "number" then warn("You should provide id or player instance to get data!") return nil end
  35. local Stats = {...}
  36. if #Stats == 0 or #Stats % 2 == 1 then warn("You should provide two or two's multiplier arguments!") return nil end
  37. if PlayerData[Player] then
  38. for i = 1, #Stats, 2 do
  39. PlayerData[Player]:Set(Stats[i], Stats[i+1])
  40. -- START OF NEW STUFF
  41. -- START OF NEW STUFF
  42. -- START OF NEW STUFF
  43. if Stats[i]=="SLP" or Stats[i]=="PvP" then weaponsEvent:FireClient(PlayerObject, Stats[i], Stats[i+1]) end
  44. -- END OF NEW STUFF
  45. -- END OF NEW STUFF
  46. -- END OF NEW STUFF
  47. end
  48. end
  49. return nil
  50. end;
  51. )
  52.  
  53.  
  54. 4. In StarterGui > SkillsGui > WeaponsController, insert this towards the top:
  55. local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
  56.  
  57.  
  58. 5. Still in StarterGui > SkillsGui > WeaponsController, insert this somewhere before function Use:
  59. local SLPvalue = 0
  60. local PvPvalue = 0
  61.  
  62.  
  63. 6. Still in StarterGui > SkillsGui > WeaponsController, in function Use, replace the two CallServer conditionals with this:
  64. if PvPvalue == 1 then
  65. if SLPvalue == 0 and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
  66.  
  67. (the old and new versions of these conditionals should look very similar)
  68.  
  69.  
  70. 7. Still in StarterGui > SkillsGui > WeaponsController, at the bottom, add this:
  71. weaponsEvent.OnClientEvent:Connect(function(...)
  72. local args = {...}
  73. --[1]: the name of a stat
  74. --[2]: the stat's new value
  75.  
  76. if args[1]=="SLP" then
  77. SLPvalue = args[2]
  78. elseif args[1]=="PvP" then
  79. PvPvalue = args[2]
  80. end
  81. end)
  82.  
  83.  
  84.  
  85.  
  86. ok system done lets go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement