Input Object = nil

Server:

local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")

--// -- // SERVICES // ---- //
local runService = game:GetService("RunService")
local repStorage = game:GetService("ReplicatedStorage")

--// -- // EVENTS // ---- //
local inputEvent = repStorage:WaitForChild("Input")

--// -- // RAYCASTING // ---- //
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
raycastParams.FilterDescendantsInstances = {char} 

-- // DISTANCES // --
local distToRCDown = 10 
local distToRCSide = 5

local canWallrun = false 

-- //// CODE //// -- //
function checkForWallrun()
	local rayDirectionDown = Vector3.new(0, -1, 0) * distToRCDown
	local rayDirectionLSide = hrp.CFrame.RightVector * -distToRCSide
	local rayDirectionRSide = hrp.CFrame.RightVector * distToRCSide

	-- Raycast down, left, and right
	local raycastResultDown = workspace:Raycast(hrp.Position, rayDirectionDown, raycastParams)
	local raycastResultLSide = workspace:Raycast(hrp.Position, rayDirectionLSide, raycastParams)
	local raycastResultRSide = workspace:Raycast(hrp.Position, rayDirectionRSide, raycastParams)

	if raycastResultDown then
		canWallrun = false -- On the ground, cannot wallrun
	elseif raycastResultLSide or raycastResultRSide then
		canWallrun = true -- Not on the ground, but near a wall
	else
		canWallrun = false -- Not near a wall or on the ground
	end
end

local function checkSec(plr)
	if game:GetService("Players"):GetPlayerFromCharacter(char) == plr then
		return
	else
		plr:Kick("Cheater.")
	end
end


-- Function to handle input
local function Input(player, input, gpe)
	checkSec(player)
	print(player.Name)
	print(input)
	print(gpe)

	---- Check if input is a keyboard input
	--if input.UserInputType == Enum.UserInputType.Keyboard then
	--	-- Now safely check the KeyCode
	--	if canWallrun and input.KeyCode == Enum.KeyCode.Space then
	--		print("Wallrunning!")
	--	end
	--end
end

-- Connect the InputBegan event once
inputEvent.OnServerEvent:Connect(Input)
-- Connect to the Heartbeat event for constant updates
runService.Heartbeat:Connect(checkForWallrun)

Local:

local repStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local event = repStorage:WaitForChild("Input")

UIS.InputBegan:Connect(function(input, gpe)
	event:FireServer(input, gpe)
end)

For some reason, input is always received as nil (gameprocessed however returns itself normally). Why? It used to work in a different game.

Have you tried printing input.KeyCode instead of input?

Or just pass in input.KeyCode in the :FireServer() method rather than input.

Roblox has parameter limitations when firing things to the server or client. Why don’t you do the input stuff on the client and then fire to the client later?

Hmm, I should’ve tried that. I currently cannot access my PC for a while as I had to get off recently, but I’ll RSVP on that.

1 Like

I could try that as a last resort should I need to.

Are you doing this to avoid exploiters firing the wrong info?

Edit: Btw the event will fire like crazy for every type of input a player does and this will significantly hinder game performance

Ah, I should indeed probably limit the keycodes to a select few.

I’ve fixed the issue! I simply sent the keycode instead of the object itself, as well as checked for the input type on the client.

Isn’t that what @astrovue said?

1 Like

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