Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is a system that allows you to reduce latency to near-0 in PA's attack system.
- 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.
- The script yields every time a call is made, since it has to get data from the server...
- ...however, doing this just 1 time can give you ~100 ms of latency even in a fresh and unlaggy server.
- The new system makes 0 calls to the server and instead updates the data dynamically.
- Enjoy!
- 1. Navigate to ReplicatedStorage. Create a RemoteEvent parented to it. Rename this RemoteEvent to "WeaponStatsEvent".
- 2. In ServerScriptService > Stats, insert this towards the top:
- local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
- 3. Still in ServerScriptService > Stats, scroll down to function SetStat at the bottom of the script.
- Right before the first line of SetStat, put this:
- local PlayerObject = Player
- Then, in the for-loop later in SetStat, put this:
- if Stats[i]=="SLP" or Stats[i]=="PvP" then weaponsEvent:FireClient(PlayerObject, Stats[i], Stats[i+1]) end
- (SetStat should now look like this, with new additions marked:
- SetStat = function(Player, ...)
- -- START OF NEW STUFF
- -- START OF NEW STUFF
- -- START OF NEW STUFF
- local PlayerObject = Player
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- pcall(function() Player = Player.UserId end)
- if type(Player) ~= "number" then warn("You should provide id or player instance to get data!") return nil end
- local Stats = {...}
- if #Stats == 0 or #Stats % 2 == 1 then warn("You should provide two or two's multiplier arguments!") return nil end
- if PlayerData[Player] then
- for i = 1, #Stats, 2 do
- PlayerData[Player]:Set(Stats[i], Stats[i+1])
- -- START OF NEW STUFF
- -- START OF NEW STUFF
- -- START OF NEW STUFF
- if Stats[i]=="SLP" or Stats[i]=="PvP" then weaponsEvent:FireClient(PlayerObject, Stats[i], Stats[i+1]) end
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- end
- end
- return nil
- end;
- )
- 4. In StarterGui > SkillsGui > WeaponsController, insert this towards the top:
- local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
- 5. Still in StarterGui > SkillsGui > WeaponsController, insert this somewhere before function Use:
- local SLPvalue = 0
- local PvPvalue = 0
- 6. Still in StarterGui > SkillsGui > WeaponsController, in function Use, replace the two CallServer conditionals with this:
- if PvPvalue == 1 then
- if SLPvalue == 0 and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
- (the old and new versions of these conditionals should look very similar)
- 7. Still in StarterGui > SkillsGui > WeaponsController, at the bottom, add this:
- weaponsEvent.OnClientEvent:Connect(function(...)
- local args = {...}
- --[1]: the name of a stat
- --[2]: the stat's new value
- if args[1]=="SLP" then
- SLPvalue = args[2]
- elseif args[1]=="PvP" then
- PvPvalue = args[2]
- end
- end)
- ok system done lets go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement