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

Why can't I put this IF statement in one line? It doesn't work if I do so.

Asked by 5 years ago

I am trying to make an If statement. When a player joins it will check if the player name is equal to my and another account. I tried using or but it doesn't work. I always have to do the same thing again in another elseif instead of just using or. Is there a way I can use or instead of having the need to type the code again?

Here is the script:

-- The dev variables are defined above this function.

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == dev then
        local clone  = game:GetService("ServerStorage").GUIs.GiveCash:Clone()
        clone.Parent = plr.PlayerGui
    elseif plr.Name == devv then
        local clone  = game:GetService("ServerStorage").GUIs.GiveCash:Clone()
        clone.Parent = plr.PlayerGui
    end
end)

Why can't I just use simple or. It just doesn't work. It doesn't give any errors, but executes the code even when the condition is false.

Any type of help is appreciated!

1 answer

Log in to vote
1
Answered by 5 years ago
-- The dev variables are defined above this function.

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == dev or plr.Name == devv then -- Add "or" to statement
        local clone  = game:GetService("ServerStorage").GUIs.GiveCash:Clone()
        clone.Parent = plr.PlayerGui
    end
end)

If this helped, make sure to upvote/accept it! Thanks!

Ad

Answer this question