Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 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):

01for 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         =   finalLocation.x - (finalLocation.x*2) -- to give a positive number
13      end
14      if z < 0 then
15         =   finalLocation.z - (finalLocation.z*2)  
View all 35 lines...

Thanks,

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

3 answers

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

Why do you have to go through all that trouble?

Can't you just do something as simple as

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

or

01MAX_WALKSPEED = 30
02while 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
11end

By the way, the answer is

1for index, player in pairs(game:GetService('Players'):GetPlayers()) do
2end--.
0
Brilliant, kudos! But this only works on studio and not the actual game (second script) jack001214 19 — 6y
0
I got working lol. Thanks! jack001214 19 — 6y
0
This actually isn't the best answer. papasherms 168 — 6y
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 — 6y
View all comments (5 more)
0
I completely forgot about the existance of the changed event. Oopsies. Fifkee 2017 — 6y
0
And FYI, you cannot kick a player with a Local Script. papasherms 168 — 6y
0
indeed i have seen issues with While loops in Roblox and is what is the 'changed event' jack001214 19 — 6y
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 — 6y
0
ill avoid Local Scripts Much as possible due to them being a number one source of being disassembled jack001214 19 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

put in serverscriptservice ?

Log in to vote
0
Answered by 6 years ago
Edited 6 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.

1local plrs = game:GetService("Players"):GetPlayers()
2 
3for i = 1, #plrs do
4    local p = plrs[i] -- Player Value
5    -- Do whatever
6end
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 — 6y
0
Mine doesn't return two values. I'm making my own value while running through the table. papasherms 168 — 6y
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 — 6y
0
without a while loop (if possible) jack001214 19 — 6y
View all comments (3 more)
0
As Firkee said its 'not efficient ' jack001214 19 — 6y
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 — 6y
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 168 — 6y

Answer this question