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

Why are both statements running in this script?

local datastoreservice = game:GetService("DataStoreService"):GetDataStore("hidden")

local allowed = {"name","name"}

game.Players.PlayerAdded:Connect(function(player)
    for i, v in pairs(allowed) do
        if player.Name == v then
            script.KickGui:Clone().Parent = player.PlayerGui
        else
        end
    end
end)

game.ReplicatedStorage.KickPlayer.OnServerEvent:Connect(function(player, playerToKick, reason)
    for i, v in pairs(allowed) do
        if player.Name == v then
            game.Players:FindFirstChild(playerToKick):Kick(reason)
        else
            datastoreservice:SetAsync(player.UserId,true)
            player:Kick("Exploiting Remotes")
        end
    end
end)

I'm trying to detect that when a player who isn't admin runs the Kick remote it will ban them from the game. When an admin fires the remote, however, it runs both statements even though their name is allowed. Without the else statement the script works fine in that it stops non-admins from kicking however I want to also ban them.

Edit: Lines 14-23 is where the issue is

7 comments

0

there is 1 statement, so what is the problem?

0

there is 1 statement, so what is the problem?

0

sorry I meant that the else is running alongside the if statement

0

are you sure? try printing on both else and if statements

0

When I fire the remote as an admin it kicks the target but then bans me when it shouldnt. If I fire the remote from a non-admin account though it only bans me (which is how I want it to work)

0

Added a print to both: https://i.imgur.com/YKr9FrC.png

0

Try doing this but with an If Then statement.

1 answer

✓ Accepted answer

It's because you're looping through a table which has multiple indexes. If one name is v while the other isn't then ofc it'll do both the if and the else.

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