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 4 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

return function(Speaker, plrName )
    if plrName then
        local ThePlayer = require(script.Parent.Parent.Settings.Groups.Parser)
        local selectedPlayer = ThePlayer.Obj(plrName)
        if typeof(selectedPlayer) == "table" then
            for _, v in pairs(selectedPlayer) do
                v:BreakJoints()
            end
        else
            selectedPlayer:BreakJoints()
        end

          print( string.format("Testing command on : '%s'!", plrName) )
    else
        warn( string.format("command '%s' got invalid arguments. Skipping..", script.Name ) )
    end
end

Parser Module

local module = {}
function module.Obj(plrName)
    if plrName:lower() == "!all" then
        local AllPlayers = require(script.Parent.AllPlayers)
        return AllPlayers.Obj(plrName)
    end
end
return module

AllPlayers Module

local module = {}
function module.Obj(plrName)
local plrs = game:GetService("Players")
for i, player in pairs(plrs:GetPlayers()) do
    plrName = player.Character
    return plrName

end
end
return module

Thank you in-advance!

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

1 answer

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

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

The AllPlayers module:

local module = {}
function module.Obj(plrName)
    local characters = {}
    local plrs = game:GetService("Players")
    for i, player in pairs(plrs:GetPlayers()) do
        table.insert(characters, player.Character)
    end
    return characters
end
return 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 — 4y
Ad

Answer this question