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

Commands for Balancing teams and gearing players on command? (This time in Code Block)(BUMP)

What is wrong with the scripts?

local function reteam() 

local x = math.random(2) for _, player in next, game.Players:GetPlayers() do


 x = (x + ((player.TeamColor == BrickColor.new("White")) and 1 or 0)) player.TeamColor = BrickColor.new((player.TeamColor ~= BrickColor.new("White")) and player.TeamColor.Name or 

(((x % 2) == 0) and "Really Blue" or "Really red"))
 end
 end

local admins = {"Incrility"}

function tableContains(t, value)
 for _, v in pairs(t) do
 if v == value then return true end end return false end

function onChatted(message, player)
 if message == "!setmode rcl" and tableContains(admins, player.Name) then
 reteam() 
end 
end

Script is intended to take players from team "trainee"(The color is white) and move them to 2 other teams Red and Blue (colors are Really Red and Really blue) The teams must be equal in size also the 2 other teams TRAINER "Black" and Green (Really Green) Must not be affected... IDK what i did wrong...

And Also

local admins = {"Incrility"}
function tableContains(t, value) 
for _, v in pairs(t) do 
if v == value then
 return true
 end
 end 
return false
 end

function onChatted(message, player)

if input:sub(1, 9):lower() == "!setmode " and tableContains(admins, player.Name) then

if letters 1 to 9 are !setmode local tool = game.Lighting.tools:FindFirstChild(input:sub(10):lower())

 if tool then tool:Clone().Parent = player.backpack tool:clone().parent = game.StarterPack
 end 
end 
end

This was supposed to get the weapon named "sword" which is in Lighting under Tools and give it to player both in the backpack and starterpack... on command "!setmode Sword"

3 comments

0

Oops I forgot to remove the -- but in the actual script its removed yet it results in the same outcome...

1

Please stop re-posting the same questions. There's an 'Edit' feature.

0

I may be able to help with this, but not with your code that sloppy. Please, in the first Code Block, edit your code so that there are at least separate lines rather than one huge chunk of code. It is unreadable.

1 answer

Okay, so your team changing script is way too over complicated, there is no need for all of that math. I had a team changing script that I fixed for someone a while back that I can use, although I'm not sure if it randomizes the players or just selects the same ones every time. Nevertheless, it works, so here's a completely new script:

local trainers = {"Incrility"}
message = Instance.new("Message", Workspace)
	for i=1,#trainers do
		if trainers[i]==player.Name then
		player.Chatted:connect(onChatted)
		break
		end
	end

 function onChatted(message)
	if msg:string.sub("!setmode rcl") then
			msg.Text = "Randomizing teams..."
			a = game.Players:GetChildren()
			blueteam = 0
			redteam = 0
				for i,v in pairs(a) do --start for loop
					if v.TeamColor == BrickColor.new("White") then
						if blueteam >= redteam then --check for unbalanced teams
							v.TeamColor = BrickColor.new("Really blue")
							blueteam = blueteam + 1
						elseif redteam > blueteam then --check for unbalanced teams
							v.TeamColor = BrickColor.new("Really red")
							redteam = redteam + 1
						end --end if teams are unbalanced
					elseif v.TeamColor == BrickColor.new("Really blue") then --check for blue players
						blueteam = blueteam + 1
					elseif b.TeamColor == BrickColor.new("Really red") then --check for red players
						redteam = redteam + 1
					end
				end --end for loop
				wait(1)
				msg:Destroy()
	end
end

That SHOULD work for your team changing script, although I'm unsure because I did have to edit this script quite a bit for you.

As for your other script, your first problem is that you check if the input is !setmode, while the actual variable you have set is message. Also, your comments are not in comments, meaning errors will occur when ROBLOX tries to read lines 13-15. Here is some changed code that should hopefully work, explained in comments:

local trainers = {"Incrility"} --changed to trainers for convenience, as my scripts have used that.

for i=1,#trainers do
		if trainers[i]==player.Name then
			player.Chatted:connect(onChatted)
			break
		end
end

function onChatted(message)

	if message:string.sub(1, 9):lower() == "!setmode " then

	local tool = game.Lighting.tools:FindFirstChild(input:string.sub(10):lower()) --you forgot string.sub, just had sub

 		if tool ~= nil then --if the tool does not equal nil, aka if it exists
			tool:Clone().Parent = player.Backpack --be careful with your capitalization, you would have had several errors just because of capitalization.
			tool.Clone().Parent = game.StarterPack
		 end 
	end 

end

Now, that should work, let me know if it does not via msg on ROBLOX please.

1 comment

0

It didnt quite work due to an error... Plz do help PM me on roblox for more details

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