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

Using module scripts to run an admin script, but not functioning how it's intended to?

So i'm trying to make commands which use a grouping system but with modules. In one script holds the command - Which connects to the grouping parser after a player argument is parsed - This is then thrown into the corresponding module of which group has been selected. However, after it has reached the player category/group, i'm having trouble on returning the values to the original script for the command to take place.

For example:

Kill/!all

"!all" gets sent to the grouping "Parser" - Which then detects that we're after everyone so it goes to the "AllPlayers" module, collect all players and then... Well that bit I can't work out how to connect back to the original so it kills all players...

The kill command

return function(Speaker, plrName )

if plrName then
local ThePlayer = require(script.Parent.Parent.Settings.Groups.Parser)
  ThePlayer.Obj(plrName)
	plrName:BreakJoints()

  print( string.format("Testing command on : '%s'!", plrName) )
else

  warn( string.format("command '%s' got invalid arguments. Skipping..", script.Name ) )
end
end

The grouping Parser

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

All players module

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

end
end
return module

How do I get the All players module connect back to the original kill command to make "plrName" die...

Thank you in advance!

2 answers

✓ Accepted answer

You could change the three modules to:

The kill command

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

The grouping Parser

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

All players module

local module = {}
function module.Obj(plrName)
	local Players = game:GetService("Players")
	return Players:GetPlayers()
end
return module

With the AllPlayers module doing so little here though, it might be better to just handle the all players case in the grouping parser.

1 comment

0

Sorry but this didn't work - It gives the error of BreakJoints is not apart of player; then if I add v.Character or selectedPlayer.Character it tells me character is not part of player.. any ideas?

I found a fix using @vector3_zero's answer - Just adjusted a few key aspects:

Kill Command

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:

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

All players:

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

1 comment

0

Sorry about that - I've edited my post above to how I had meant it to be.

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