Trying to make code for when you hold z, something happens. However when I press z I don’t get pass print 1. I don’t see any issues in the code, what am I doing wrong?
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
uis.InputBegan:Connect(function(input, gameprocessedevent)
if gameprocessedevent then return end
print("1")
if input.KeyCode == script.Parent.Keybinds.ProvinceSelection.Value then
print("2")
local color
end
end)
I forgot the basics of InputBegan but I’m assuming that every time the event is fired gameprocessedevent has a value, so your guard condition would always stop the function everytime it fires
because the input keycode isn’t equal to the string values I’m assuming your using. Try this code instead:
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
uis.InputBegan:Connect(function(input, gameprocessedevent)
if gameprocessedevent then return end
print("1")
if input.KeyCode == Enum.KeyCode[script.Parent.Keybinds.ProvinceSelection.Value] then
print("2")
local color
end
end)
well if you want code when you hold z, not press it
you would use heartbeat to check if key is down
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
if UserInputService:IsKeyDown(Enum.KeyCode.Z) then
print(1)
end
end)
1st: Any error in the console?
2nd: Running the game locally?
3rd: Does the script run at all, say if you were to put a print statement in the very beginning does it print?
I suggest commenting out the gameprocessable if statement till you get it to work