The following code is a simplified version of an extract from a localscript I’m using in a grid placement system:
local LocalPlayer = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
if 2<5 then
UserInputService.InputBegan:Connect(function(input,gameproccessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Z then
print("Z was pressed")
end
end
end)
end
The problem is that the code inside the if loop is executed even when the condition is not met (in my case 2 is not greater than 5; still, when I press Z on my keyboard, the message “Z was pressed” pops up in the output).
I’ve tried making different variants of the code, but the problem persists. I’ve read the article on If Statements on the Roblox Developer Hub, and nothing there explains why this should be occurring.
It would be very helpful to me if somebody explained to me why this is happening.