Hello everyone, I’m trying to script a system that enables to lock a vehicle:
remoteEvent.OnClientEvent:connect(function(type)
if type== "Lock" then
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.K then
print("lock")
end
elseif type== "Unlock" then
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.K then
print("Unlock")
end
end
end)
I made the script minimal so that you can understand what I would like to achieve. When I use the same key, in this case K, it doesn’t work, but if I use 2 different keys it works. I would like to use the K in both cases but I can’t get it to work, any help?
Not sure what the type argument is for, but I would recommend using some kind of bool value, so if K is pressed, check if the boolValue is true, and if it is then lock the car. If it isn’t, unlock the car.
KPress = 0
remoteEvent.OnClientEvent:connect(function(type)
if type== "Lock" then
if Input.UserInputType == Enum.UserInputType.Keyboard and KPress == 0 and Input.KeyCode == Enum.KeyCode.K then
KPress = 1
print("lock")
end
elseif type== "Unlock" then
if Input.UserInputType == Enum.UserInputType.Keyboard and KPress == 1 and Input.KeyCode == Enum.KeyCode.K then
print("Unlock")
KPress = 0
end
end
end)
I do not know what you are trying to achieve but this might work.