Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Solved]what is the Best way to run for all players through server?

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):

for index, player in pairs(game.Players:GetChildren()) do -- not working i.e not looping in Studio dont know why
	
      local StartLocation = player.Character.HumanoidRootPart.Position
       
      wait(1)
      local EndLocation = player.Character.HumanoidRootPart.Position		
      local finalLocation = EndLocation - StartLocation
      local x = finalLocation.x
      local z = finalLocation.z
      print(finalLocation)
      if x < 0 then
	     x  =   finalLocation.x - (finalLocation.x*2) -- to give a positive number
      end
      if z < 0 then
         z  =   finalLocation.z - (finalLocation.z*2)	
      end
      if x > 17 then
	    player:Kick("Do not cheat")

      end
      if z > 17 then
	     player:Kick("Do not cheat")
	   
	      
      end
      if x < 17 then
	   -- break the loop and goto to the next player 
      end
      if x < 17 then
	      -- break the loop and goto to the next player 
       end
  

end
--forced  player as in 'player = jack001214' i.e working when forced 

Thanks,

2 comments

0

math.abs makes sure a number is positive

0

ahhah i knew there was a function to do this

3 answers

✓ Accepted answer

Why do you have to go through all that trouble?

Can't you just do something as simple as

while wait(1) do
   if Workspace:GetRealPhysicsFPS() > 65 then
      game.Players.LocalPlayer:Kick()
   end
end

or

MAX_WALKSPEED = 30
while wait(1) do
	for i, v in pairs(game:GetService('Players'):GetPlayers()) do
		wait()
		pcall(function(egg)
			if v.Character:WaitForChild('Humanoid').WalkSpeed > 30 then
				v:Kick('Stop exploiting, ya fatty!')
			end
		end)
	end
end

By the way, the answer is

for index, player in pairs(game:GetService('Players'):GetPlayers()) do
end--.

9 comments

0

Brilliant, kudos! But this only works on studio and not the actual game (second script)

0

I got working lol. Thanks!

0

This actually isn't the best answer.

0

You'd probably want to refrain from using a while loop because of its inefficiency. A changed event would work a lot better.

0

I completely forgot about the existance of the changed event. Oopsies.

0

And FYI, you cannot kick a player with a Local Script.

0

indeed i have seen issues with While loops in Roblox and is what is the 'changed event'

0

You can kick yourself in a localscript. also, the changed event fires when the object binded to the event changes in any way, shape, or form. if a property changes, then it will fire.

0

ill avoid Local Scripts Much as possible due to them being a number one source of being disassembled

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.

local plrs = game:GetService("Players"):GetPlayers()

for i = 1, #plrs do
	local p = plrs[i] -- Player Value
	-- Do whatever
end

7 comments

0

Pairs returns two values: The iteration, and the found item. And if you're being this technical, yours returns two values too. The iteration, and the player. /shrug

0

Mine doesn't return two values. I'm making my own value while running through the table.

0

Interesting but does this loops through each player and does it loop back again? or do i need to add a event or something when a player join/leaves or run it at an set interval

0

without a while loop (if possible)

0

As Firkee said its 'not efficient '

0

The problem is, it does return two values. https://puu.sh/ACJZf/aa64d501bb.png And even then, I don't know why you're worrying about two values. He's only worrying about using the defined "v" value and not the other defined "i" value.

0

Jack you might want to nest this in a While (wait) do end, and repying to Fifkee, if you want to "technical" your is less "efficient" becasue your running through a table, then getting two values. "i", being of the index. "v", being the variant.

This discussion is preserved as it was. New answers, comments, and votes are closed.