And I have a script that does something when the remotevent fires saying “up” or “down”. My question is, how do I tell if it fired with “up” or “down”? I want something like this (This makes no sense, but this is what I want)
if firedEvent == "up" then
print("pressed up")
end
if firedEvent == "down" then
print("pressed down")
end
This is redundant, if the first statement is true then the second statement can’t be true and vice versa, you can’t assign two values to a single argument in Lua.
Ex:
if a == 1 then
-- a can't equal 2
end
if a == 2 then
-- a can't equal 1
end
An elseif statement, and what @Dolphin_Worm did are virtually the same, one just uses the direct syntax to accomplish it’s goal.
Might I also suggest a switch statement in the case that OP is adding more functions in the future?
Ex;
local functionsTbl = {
up = function()
print("up")
end;
down = function()
print("down")
end;
left = function()
print("left")
end;
right = function()
print("right")
end;
}
RemoteEvent.OnServerEvent:Connect(function(player, direction)
if direction and functionsTbl[direction] then
functionsTbl[direction]()
end
end)
They are more or less the same, but there is one subtle difference: in the first case, only one of the two statements can be executed while in the second case it is possible for both of them to be executed.
In this example, it does not matter since the two conditions are mutually exclusive, but it may become important if it is possible for both conditions to be true. In that case, “if else if” would only execute the first “if” statement and “if if” would execute them both in sequence.