Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago
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

0
Indents are there the text is just too long tictac67 96 — 5y
0
its a local script aazkao 787 — 5y
0
Yes, in a gui tictac67 96 — 5y
0
Accept the answer mate aazkao 787 — 5y

1 answer

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
Thanks, will test this tictac67 96 — 5y
0
This works, thank you tictac67 96 — 5y
0
This only works in studio tictac67 96 — 5y
Ad

Answer this question