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

This puts me on the team even though my name is in the list, any ideas why?

local localp = game.Players.LocalPlayer
local CDName = {"JackPlaysRBYT","Pupp_err","Giptoid","ThePersonThatWorks","tictac67"}
function FP()
	for i,v in pairs(CDName) do
		if localp.Name ~= v and localp.TeamColor ~= game.Teams["Foundation Personnel"].TeamColor then
			game.Workspace.TeamChangeFE.teamchange:FireServer(game.Teams["Foundation Personnel"].TeamColor)
		end
	end
end
script.Parent["SCP"].MouseButton1Click:connect(FP)

It wont go through the whole array I think

4 comments

0

Indents are there the text is just too long

0

its a local script

0

Yes, in a gui

0

Accept the answer mate

1 answer

✓ Accepted answer

It is because that it goes through the whole array that you get put on the team, because the first index of the array is not your name, the if statement will be true and it will FireServer, and it will fire it 4 times as there is 5 indexes in the array and 4 of them are not yours

Just add a boolean that becomes true if it found your name in the array, and after the for loop ended, it checks if the boolean is true or not, if not then it will change the team.

local localp = game.Players.LocalPlayer
local CDName = {"JackPlaysRBYT","Pupp_err","Giptoid","ThePersonThatWorks","tictac67"}
local InTheList = false

function FP()
    for i,v in pairs(CDName) do
        if localp.Name == v and localp.TeamColor ~= game.Teams["Foundation Personnel"].TeamColor then
	      InTheList = true
	      break
        end
    end

    if not InTheList then
	game.Workspace.TeamChangeFE.teamchange:FireServer(game.Teams["Foundation Personnel"].TeamColor)
    end
end

script.Parent.MouseButton1Click:connect(FP)

Personally for me i would do the checking at the server side, as it is more secure.

3 comments

0

Thanks, will test this

0

This works, thank you

0

This only works in studio

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