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

Authorization script, it does both why?

I don't understand why it does both? Can you help me?

local Authorization = {"NiniBlackJackQc","Player1"}

local player = game:GetService("Players").LocalPlayer
repeat wait() until player.Character

local Character = player.Character

for i, v in pairs(Authorization) do
	if player.Name == v then
		script.Parent:Destroy()
		GameSound()
	else
		Character:Destroy()
		Instance.new("BlurEffect",workspace.CurrentCamera)
		IntroSound()
	end
end

1 answer

✓ Accepted answer

The reason it does both is because you are only one and not both:

local Authorization = {"NiniBlackJackQc","Player1"}

local player = game:GetService("Players").LocalPlayer
repeat wait() until player.Character

local Character = player.Character

for i, v in pairs(Authorization) do
    if player.Name == v then
        script.Parent:Destroy()
        GameSound()
	break; -- This stops the loop from running anymore.
    else
        Character:Destroy()
        Instance.new("BlurEffect",workspace.CurrentCamera)
        IntroSound()
	break;
    end
end

It was checking all the names in the Authorization table, and you only matched one and not both. So it ran both. I hope this helped. If it did please accept this as the answer so others know your problem has been solved. If you are confused or have any other questions feel free to ask.

1 comment

0

you use breaks in loops, not return..

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