Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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,

0
math.abs makes sure a number is positive tobyjing2005 107 — 2y
0
ahhah i knew there was a function to do this jack001214 19 — 2y

3 answers

Log in to vote
3
Answered by
Fifkee 2017 Administrator Moderation Voter Community Moderator
2 years ago

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--.
0
Brilliant, kudos! But this only works on studio and not the actual game (second script) jack001214 19 — 2y
0
I got working lol. Thanks! jack001214 19 — 2y
0
This actually isn't the best answer. papasherms 101 — 2y
0
You'd probably want to refrain from using a while loop because of its inefficiency. A changed event would work a lot better. Precisionly 103 — 2y
View all comments (5 more)
0
I completely forgot about the existance of the changed event. Oopsies. Fifkee 2017 — 2y
0
And FYI, you cannot kick a player with a Local Script. papasherms 101 — 2y
0
indeed i have seen issues with While loops in Roblox and is what is the 'changed event' jack001214 19 — 2y
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. Fifkee 2017 — 2y
0
ill avoid Local Scripts Much as possible due to them being a number one source of being disassembled jack001214 19 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

put in serverscriptservice ?

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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
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 Fifkee 2017 — 2y
0
Mine doesn't return two values. I'm making my own value while running through the table. papasherms 101 — 2y
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 jack001214 19 — 2y
0
without a while loop (if possible) jack001214 19 — 2y
View all comments (3 more)
0
As Firkee said its 'not efficient ' jack001214 19 — 2y
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. Fifkee 2017 — 2y
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. papasherms 101 — 2y

Answer this question