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

Why does my kill command only kill the player saying it and not everyone?

Asked by 5 years ago

I'm trying to make admin commands by linking modules to different sections.

So far, my script connects to the correct command module, which then brackets off to the parser which determines what player/group it's going to perform the command on, it then brackets off to the player/group module which then tells the script how it's going to run; Eg. Group: All - would select all players - It would then return that module back to the original kill module and kill everyone...

However, the modules aren't working in the correct way and is only causing the speaker to die instead of the whole server.. Any ideas?

Kill Command Module

01return function(Speaker, plrName )
02    if plrName then
03        local ThePlayer = require(script.Parent.Parent.Settings.Groups.Parser)
04        local selectedPlayer = ThePlayer.Obj(plrName)
05        if typeof(selectedPlayer) == "table" then
06            for _, v in pairs(selectedPlayer) do
07                v:BreakJoints()
08            end
09        else
10            selectedPlayer:BreakJoints()
11        end
12 
13          print( string.format("Testing command on : '%s'!", plrName) )
14    else
15        warn( string.format("command '%s' got invalid arguments. Skipping..", script.Name ) )
16    end
17end

Parser Module

1local module = {}
2function module.Obj(plrName)
3    if plrName:lower() == "!all" then
4        local AllPlayers = require(script.Parent.AllPlayers)
5        return AllPlayers.Obj(plrName)
6    end
7end
8return module

AllPlayers Module

01local module = {}
02function module.Obj(plrName)
03local plrs = game:GetService("Players")
04for i, player in pairs(plrs:GetPlayers()) do
05    plrName = player.Character
06    return plrName
07 
08end
09end
10return module

Thank you in-advance!

0
It seems to be returning a tuple, not a table. User#30567 0 — 5y
0
How would I go about returning a table rather than the tuple? xXTouchOfFrostXx 125 — 5y
0
Also could you explain what a tuple is please as i'm not quite sure.. xXTouchOfFrostXx 125 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

AllPlayers is only returning one player. the return is breaking the loop.

The AllPlayers module:

01local module = {}
02function module.Obj(plrName)
03    local characters = {}
04    local plrs = game:GetService("Players")
05    for i, player in pairs(plrs:GetPlayers()) do
06        table.insert(characters, player.Character)
07    end
08    return characters
09end
10return module

have a nice day. I don't know what tuples have to do with this.

0
You legend! thank you so much! xXTouchOfFrostXx 125 — 5y
Ad

Answer this question