BAE Trainer System

Trying to develop a script which will change someone’s overhead tag to “trainer” on command from Basic Admin

I’ve attached the script and the error I get when running. Thanks in advance

local function pluginFunction(Args) -- keep the name of the function as "pluginFunction"
		local Player = Args[1]
		if Args[3] then
			local target = returnPlayers(Player, Args[3]) if not target then return end
			local combinedVictims = ''
			for a,b in pairs(target) do
				if combinedVictims == '' then
					combinedVictims = b.Name
				else
					combinedVictims = combinedVictims..', '..b.Name
				end
			end

			for a,b in pairs(Args) do
				remoteEvent:FireClient(Player, 'Hint', 'Set Role', 'Success')
				b.Name.Character.Head.Rank.Frame.Group.Text = "TRAINER"
			end				
		end
	end
1 Like

Try this

local function pluginFunction(Args) – keep the name of the function as “pluginFunction”
local Player = Args[1]
if Args[3] then
local target = returnPlayers(Player, Args[3]) if not target then return end
local combinedVictims = ‘’
for a,b in pairs(target) do
if combinedVictims == ‘’ then
combinedVictims = b.Name
else
combinedVictims = combinedVictims…', '…b.Name
end
end

  	for a,b in pairs(Args) do
  		remoteEvent:FireClient(Player, 'Hint', 'Set Role', 'Success')
  		b.Character.Head.Rank.Frame.Group.Text = "TRAINER"
  	end				
  end

end

Delete my whole script and only put that in?

Change this:

b.Name.Character.Head.Rank.Frame.Group.Text = "TRAINER"

to this:

b.Character.Head.Rank.Frame.Group.Text = "TRAINER"

The reason it’s not working is that b.Name is the player’s name which is a string and isn’t an Instance that has the Character property.

Thanks for the solution, it now partly works.
But:
I’m still getting the same error if I’m running it on someone else (“train Iv_”). But running just “train” on myself works.

Is the command used like this: :trainer (username)?

Assuming it’s :trainer (username), you can go ahead and try this out:

local function pluginFunction(Args) -- keep the name of the function as "pluginFunction"
		local Player = table.remove(Args, 1)
		local Victims = returnPlayers(Player, Args[2] or '') 

		if not Victims then
			return remoteEvent:FireClient(Player, 'Hint', 'Error', 'Please provide a valid username.')
		end

		for a,b in next,Victims do
			remoteEvent:FireClient(Player, 'Hint', 'Set Role', 'Success')
			b.Character.Head.Rank.Frame.Group.Text = "TRAINER"
		end			
	end

Alrighty, I can help with this since I have been modifying BAE quite a lot.

To start off, Args is just a table of strings of each word in the message. So, you are actually looping through strings, not the Player’s Charafcter. So, you have to replace:

for a,b in pairs(Args) do —> for a,b in pairs(target) do

You could also delete the variable combinedTargets and the loop of it since it is not necessary for your code to work.

There is one problem with your code though. Since it is looping through the table, remoteEvent:FireClient(Player, 'Hint', 'Set Role', 'Success') will fire amount to how many targets you have. I suggest putting after the loop, or do necessary checks like if:

  1. There is a valid target/s
  2. It successfully changed the Text to “Trainer”

Thanks a bunch! Works great - really appreciate it.

1 Like

No problem, glad that I was able to help! :smile:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.