Printing as equal, but returns nil when actually compared

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to make a generator system like dead by daylight, where you use a proximity prompt to start working on a generator, and just move to un-interact with the generator. Problem is, you can’t use UIS in server scripts (as far as I’m aware) so I’m using a remote function to go to a local script in StarterPlayerScripts, detect all input during interaction, and if it’s keyboard input, return true back to the server script.

  1. What is the issue? Include screenshots / videos if possible!

When I print(input.UserInputType == Enum.UserInputType.Keyboard), it prints as true when I use my keyboard during the function, but when I actually compare it and print out the result in the server script, it returns as nil. No matter what I press it shows as nil in the output.

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

I’ve added a debounce, changed the loop times, tried to isolate the problem like 20 times by now, no matter what I do nothing works, and if it does, a new problem arises. I’ve read the documentation over for functions and UIS, but I don’t see what I’m doing wrong.

The code is down below, and I’ve reviewed it so much and can’t figure out what’s wrong with it, or what concept I’m overlooking, please help me out.

detectInput.OnClientInvoke = function()
	
	if debounce == false then
		debounce = true
		
		UIS.InputBegan:Connect(function(input)
			print("input began")
			
			print(input.UserInputType == Enum.UserInputType.Keyboard)

			if input.UserInputType == Enum.UserInputType.Keyboard then
				debounce = false
				return true
			elseif input.UserInputType ~= Enum.UserInputType.Keyboard then
				debounce = false
				return false
			end		
		end)
	end

end


-- heres where i call the function in a server script

		local inputRecieved = false
		
		while inputRecieved == false or inputRecieved == nil do
			
			inputRecieved = detectInput:InvokeClient(plr)
			
			print(inputRecieved)
			
			if inputRecieved == true then
				plr.Character.Humanoid.WalkSpeed = 16
				usingValue:Destroy()
				
				break	
			end	
			task.wait()
		end

you have to add keybind you want to work for example if inp.KeyCode == Enum.KeyCode.R then end
or if you have table they use if inp.KeyCode == ExampleTable[Enum.KeyCode.Name] then end
Remember That userinput type is only for mouse

I think I’m misunderstanding sorry, I put it as


			if input.KeyCode == Enum.KeyCode.Space then
				debounce = false
				return true
			else
				debounce = false
				return false
			end		

but it’s the exact same, prints as true but returns nil

Function Binds.rbxl (48.5 KB)
here i made place for you to check

there is a script inside StarterCharacterScripts

It is not working, so I think it’s a problem with how I’m looping it, I don’t know what though I’ve been trying for 3 hours now

okay from what i see you want to get input from client on server instead of using BindableFunction Remote you can use normal Remote. idk is this what you meant but here is updated version of that previous place
TestPlace.rbxl (49.8 KB)

if you want every input to be send then replace in local script after input began with remote:FireServer(inp.KeyCode.Name)

2 Likes

thank you so much for your help, I was able to get it working with this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.