InputBegan not working

Hey there!

So, i have a a user input thing where it sends a remote event to the server.

It doesn’t work, lets say if i press “R” and then i press “A” after, character will go left.

i press “R” and then “A” and it doesn’t work.

Heres the code

Stop wallrun

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WallrunRemote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("WallrunRemoteStop")
local WallrunRemote2 = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("WallrunKey")

local CoolDown = false
local CoolDown2 = false

local printer = false

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.R and gameProcessed == false and CoolDown == false then
		CoolDown = true
		WallrunRemote:FireServer()
		
		UserInputService.InputBegan:Connect(function(input,gameProcessed)
			if CoolDown2 == false and input.KeyCode ~= Enum.KeyCode.R then
				CoolDown2 = true
				if gameProcessed then return end
				if printer then
					print((input.KeyCode))
				end
				WallrunRemote2:FireServer(input.KeyCode)
				
				task.spawn(function()
					task.wait(.1)
					CoolDown2 = false
				end)
			end
		end)
		task.spawn(function()
			task.wait(.1)
			CoolDown = false
		end)
	end
end)

Start wallrun code:

local UserInputService = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local WallrunRemote = Remotes:WaitForChild("WallrunRemote")
local WallrunRemoteStop = Remotes:WaitForChild("WallrunRemoteStop")
local WallrunTilt = Remotes:WaitForChild("WallrunTilt")
local value = script.Parent:WaitForChild("eValue")

local Character = script.Parent.Parent.Parent
local HRP = Character:WaitForChild("HumanoidRootPart")

local W = Enum.KeyCode.W
local A = Enum.KeyCode.A
local D = Enum.KeyCode.D

local CoolDown = false

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.E and gameProcessed == false and value.Value == false and CoolDown == false then
		CoolDown = true
		WallrunRemote:FireServer()
		task.spawn(function()
			task.wait(.1)
			CoolDown = false
		end)
	end
end)

(Note: everything is on starter character script and is local script)

Thanks!!

this is probably how the top script should be coded you had it with another inputbegan connection being made inside the first also you had a gameprocess return in the 2nd that would cause the cooldown2 to never become false again

Also I think you should take these 2 scripts use one userinpuservice connection and do everthing from there don’t see the need in 2 local scripts here

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WallrunRemote = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("WallrunRemoteStop")
local WallrunRemote2 = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("WallrunKey")

local CoolDown = false
local CoolDown2 = false

local printer = false

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.R and gameProcessed == false and CoolDown == false then
		CoolDown = true
		WallrunRemote:FireServer()

		task.spawn(function()
			task.wait(.1)
			CoolDown = false
		end)
	elseif CoolDown2 == false and input.KeyCode ~= Enum.KeyCode.R and gameProcessed == false then
		CoolDown2 = true
		if printer then
			print((input.KeyCode))
		end
		WallrunRemote2:FireServer(input.KeyCode)

		task.spawn(function()
			task.wait(.1)
			CoolDown2 = false
		end)
	end
end)
1 Like

if you need both these statements checked just set as if not elseif

1 Like

Still same problem, first try, doesn’t work.

Second try, works somehow.

Heres the server listener:

local function Space(tablexd,HRP)
	WallrunRemoteStop.OnServerEvent:Connect(function(plr)
		if printer then
			print("r pressed")
		end
		WallrunRemote2.OnServerEvent:Connect(function(plr,key)
			if printer then
				print(key)
			end
			remove(HRP,tablexd,plr,key)
		end)
	end)
end

What it prints (printer on for both)
image

maybe i could put the keys down to one remote, if key is not R then bla bla bla. Not sure if it’ll work, tell me if i should do that or not

1 Like

you shouldn’t have these connections inside of a function unless it is only going to be run once

then you have this one inside of the top connection which if you run that function create a connection to the first each time it runs then if this remote is called it creates the connection to the 2nd remote every time its called

these should all be delayed separately. its kinda the same issue you had on the local scripts

should look more like this:

WallrunRemoteStop.OnServerEvent:Connect(function(plr)
	if printer then
		print("r pressed")
	end
end)

WallrunRemote2.OnServerEvent:Connect(function(plr,key)
	if printer then
		print(key)
	end
	remove(HRP,tablexd,plr,key)
end)
1 Like

function is only run once for the table

Improvized to this:

local function Space(tablexd,HRP)
	local rPressed = false
	WallrunRemoteStop.OnServerEvent:Connect(function(plr)
		if printer then
			print("r pressed")
			rPressed = true
		end
	end)
	
	WallrunRemote2.OnServerEvent:Connect(function(plr,key)
		if printer then
			print(key)
		end
		if rPressed then
			remove(HRP,tablexd,plr,key)
		end
	end)
end

still does not work sadly

are you sure space function is being run to make the connections?
it has to run before any of the client side remotes are fired

1 Like
WallrunRemote.OnServerEvent:Connect(function(plr,e) --when player presses a movement key	
	local tablexd = {
		created = false,
		bodyVelocity1 = nil,
		debounceRight = false,
		debounceLeft = false,
		left = false,
		right = false,
		left2 = false,
		right2 = false,
		anim1 = nil,
		speed = 30,
		passed = 0

	}
	
		local ft = tick()
		local HRP = plr.Character:WaitForChild("HumanoidRootPart")
		local hum = plr.Character:WaitForChild("Humanoid")
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {HRP.Parent}
		local rayDirection = Vector3.new(0,0,-2)
		local wallRight = workspace:Raycast(HRP.CFrame.Position, HRP.CFrame.RightVector * rayDis, raycastParams)
		local wallLeft = workspace:Raycast(HRP.CFrame.Position, HRP.CFrame.RightVector * -rayDis, raycastParams)
	
	Space(tablexd,HRP)

yes, it is called when the wallrun starts

those should not be declared like that but by their self same as the one you just posted
if you do call it like this then the connection is not made until then also it is made multiple times

1 Like

actually fixed it by

local function Space(tablexd,HRP)
	local rPressed = false
	WallrunRemoteStop.OnServerEvent:Connect(function(plr,key)
		if printer then
			print("r pressed")
		end
		
		if key == Enum.KeyCode.R then
			rPressed = true
		end
		
		if key ~= Enum.KeyCode.R and rPressed and key == W or key == A or key == D then
			remove(HRP,tablexd,plr,key)
		end
	end)
end

thanks so much for the help, wouldn’t have found the idea without your help!