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

Why are both statements running in this script?

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

0
there is 1 statement, so what is the problem? raid6n 2196 — 3y
0
there is 1 statement, so what is the problem? raid6n 2196 — 3y
0
sorry I meant that the else is running alongside the if statement ItsDDog 7 — 3y
0
are you sure? try printing on both else and if statements raid6n 2196 — 3y
View all comments (3 more)
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) ItsDDog 7 — 3y
0
Added a print to both: https://i.imgur.com/YKr9FrC.png ItsDDog 7 — 3y
0
Try doing this but with an If Then statement. ghxstlvty 133 — 3y

1 answer

Log in to vote
1
Answered by
zadobyte 692 Moderation Voter
3 years ago

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.

Ad

Answer this question