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

Why is my if statement not working correctly?

Asked by
Txeer 46
5 years ago

When this code runs the GUI will become not visible but it will still kick the player after twenty seconds? Why?

if game.Players.LocalPlayer.UserId == 85907087 or 45119661 or 636062412 then
    script.Parent.Visible = false
end

if game.Players.LocalPlayer.UserId ~= 85907087 or 45119661 or 636062412 then
    print("script ran")
    script.Parent.Info.Text = "You will be automatically kicked in 20 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 19 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 18 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 17 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 16 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 15 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 14 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 13 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 12 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 11 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 10 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 9 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 8 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 7 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 6 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 5 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 4 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 3 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 2 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 1 second."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 0 seconds."
    game.Players.LocalPlayer:Kick("You have been automatically kicked")
end

2 answers

Log in to vote
0
Answered by 5 years ago

Try this: (I simplified the code)

local whitelist = {85907087,45119661,636062412}
local isInWhite = false
for _, v in pairs(whitelist) do
    if game.Players.LocalPlayer.UserId == v then
        isInWhite = true
    end
end
if isInWhite == false then
    for i = 20,1,-1 do
        script.Parent.Info.Text = "You will be automatically kicked in "..i.." seconds."
    wait(1)
    end
    game.Players.LocalPlayer:Kick()
end

If this doesn't work then try firing the kick from server or check for errors, it might just be the ors in your code that isn't making it work, if this works click accept

Ad
Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago

Because after you first check with the userid, you then check individual numbers.

if game.Players.LocalPlayer.UserId == 85907087 or game.Players.LocalPlayer.UserId ==45119661 or game.Players.LocalPlayer.UserId ==636062412 then
    script.Parent.Visible = false
end

if game.Players.LocalPlayer.UserId ~= 85907087 or game.Players.LocalPlayer.UserId ~=45119661 or game.Players.LocalPlayer.UserId ~=636062412 then
    print("script ran")
    script.Parent.Info.Text = "You will be automatically kicked in 20 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 19 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 18 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 17 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 16 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 15 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 14 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 13 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 12 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 11 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 10 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 9 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 8 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 7 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 6 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 5 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 4 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 3 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 2 seconds."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 1 second."
    wait(1)
    script.Parent.Info.Text = "You will be automatically kicked in 0 seconds."
    game.Players.LocalPlayer:Kick("You have been automatically kicked")
end

Answer this question