Hello i am working on an 'antiSpeed' type exploit thing and i want to know what is the best way to run this script for all the players at the same time ( and of course improvements):
01 | for index, player in pairs (game.Players:GetChildren()) do -- not working i.e not looping in Studio dont know why |
02 |
03 | local StartLocation = player.Character.HumanoidRootPart.Position |
04 |
05 | wait( 1 ) |
06 | local EndLocation = player.Character.HumanoidRootPart.Position |
07 | local finalLocation = EndLocation - StartLocation |
08 | local x = finalLocation.x |
09 | local z = finalLocation.z |
10 | print (finalLocation) |
11 | if x < 0 then |
12 | x = finalLocation.x - (finalLocation.x* 2 ) -- to give a positive number |
13 | end |
14 | if z < 0 then |
15 | z = finalLocation.z - (finalLocation.z* 2 ) |
Thanks,
Why do you have to go through all that trouble?
Can't you just do something as simple as
1 | while wait( 1 ) do |
2 | if Workspace:GetRealPhysicsFPS() > 65 then |
3 | game.Players.LocalPlayer:Kick() |
4 | end |
5 | end |
or
01 | MAX_WALKSPEED = 30 |
02 | while wait( 1 ) do |
03 | for i, v in pairs (game:GetService( 'Players' ):GetPlayers()) do |
04 | wait() |
05 | pcall ( function (egg) |
06 | if v.Character:WaitForChild( 'Humanoid' ).WalkSpeed > 30 then |
07 | v:Kick( 'Stop exploiting, ya fatty!' ) |
08 | end |
09 | end ) |
10 | end |
11 | end |
By the way, the answer is
1 | for index, player in pairs (game:GetService( 'Players' ):GetPlayers()) do |
2 | end --. |
This is the fastest way to loop through something because you're not using pairs or ipairs or next, which are all functions which return two values.
1 | local plrs = game:GetService( "Players" ):GetPlayers() |
2 |
3 | for i = 1 , #plrs do |
4 | local p = plrs [ i ] -- Player Value |
5 | -- Do whatever |
6 | end |