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

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

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

✓ Accepted answer
-- 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!

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