User input Service not detecting

Hey Developers,
I have some issue with input service .It didn’t detect when player pressing E. No error was found and I tried do debugging and found that the script at line 17 didn’t print at all. I cant find any solution for my problem .This is my script:

local player = game.Players.LocalPlayer

local bill = script.Parent.BillboardGui
local but = bill.TextButton

local doorparent = game.Workspace.Door


local UseInputService = game:GetService("UserInputService")


UseInputService.InputBegan:Connect(function(input, gameproces)
	if not gameproces then
		for i , v in pairs(doorparent:GetChildren())do
			if (player.Character.HumanoidRootPart.Position - v.Door.Position).Magnitude < 15 then
				print("nearby passenger")
				if bill.Adornee ~= v then
					print("xeneser")
					print("ok")
					bill.Adornee = v
					print("k")
					if input.KeyCode == Enum.KeyCode.E  and bill.Adornee == v then
						print("buur")
						game.ReplicatedStorage.RemoteEvent.OpenDoorEvent.OpenDoorBar:FireServer(v.Hinge)
						print(bill.Adornee)

					end
				end
			end
		end
	end			
end)

Hope to find any solution :grinning: :grinning:

1 Like

Can you tell us which is like 17?

print("buur")

do you mean this??

It’s likely because the other half of the logic statement isn’t true, did you check to see the Adornee?

I did check and it changed when player is nearby

I’d remove that portion of the logic statement, it’s a bit redundant especially in this context since you did set the adornee in an earlier line.

I removed

and bill.Adornee == v

but still same
It didn’t detect when I pressing E

Put the logical statement where you check the KeyCode at the way beginning, before the gameproces check. It’s likely that you’re checking too late.

It did print but the remote event wont run

Show me the updated code with all the changes.

local player = game.Players.LocalPlayer

local bill = script.Parent.BillboardGui
local but = bill.TextButton

local doorparent = game.Workspace.Door


local UseInputService = game:GetService("UserInputService")


UseInputService.InputBegan:Connect(function(input, gameproces)
	for i , v in pairs(doorparent:GetChildren())do
		if (player.Character.HumanoidRootPart.Position - v.Door.Position).Magnitude < 15 then
			bill.Adornee = v
			print("nearby passenger")
		if not gameproces then
			if input.KeyCode == Enum.KeyCode.E then
				if bill.Adornee == v then					
					print(v)
					wait(.5)
					print("xeneser")
					print("buur")
					game.ReplicatedStorage.RemoteEvent.OpenDoorEvent.OpenDoorBar:FireServer(v.Hinge)
					print(bill.Adornee)

						end
					end
				end
			end
    	end			
   end)

When I’m firing remote event it didnt fired but it only print instead

Are there any errors occurring?

there aren’t it print instead

Which prints aren’t occurring, if they all are occurring, then the remote event is firing and there’s something wrong with the receiving of your remote event.

local tweenService = game:GetService("TweenService")
local ti = TweenInfo.new(1)


local function StartTween(part)
	
	local hinge = part
	
	local goal = {}
	goal.CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(-90),0)
	
	local ended = {}
	ended.CFrame = hinge.CFrame * CFrame.Angles(0,0,0)
	
	local startingtween = tweenService:Create(hinge,ti,goal)
	local edningtween = tweenService:Create(hinge,ti,ended)
end



game.ReplicatedStorage.RemoteEvent.OpenDoorEvent.OpenDoorBar.OnServerEvent:Connect(function(StartTween)
	print("bruh im not running")
end)

it print at the last line

Your code needs a lot of refactoring! It is hard to read and that’s why it comes hard to find a solution to your problem, one thing is that you should use guard clauses within this portion. Example:

UserInputService.InputBegan:Connect(function(input, gameProcessEvent)
    if gameProcessEvent then return end
end)

This avoids nested if logic and it is better to our eyes, to be honest. Is basically checking if gameProcessEvent it is true and ending the function if that’s the case!

Ah I see the issue, your first parameter needs to be the player, secondly you’re sending the hinge of the door so it can’t be the start tween as the parameter. Inside the remote event function, then you can call the StartTween function

Can you explain “gameProcessEvent”? I never really understood and I find it confusing. If you don’t mind of course.

Yes no problem! Basically the parameter gameProcessEvent refers to the game engine that got this input and acted on it. Lets have an example, if a button was pressed within this input, gameProcessEvent will be true, also this is when we’re chatting. When we are using the chat to communicate with other players and you put some input (like if our input detection was the E) and we pressed the E while doing so, the parameter gameProcessEvent will be true.

The InputBegan it is fired everytime there’s any input registration by the engine it-self.

2 Likes

Agreed with him, you can’t put the function keyword and then put the name of the function where the parameters should go. The OnServerEvent always takes in a player as the first parameter as well. So you would send StartTween(player, args).