Help with fireserver() argument, inputting keys

Im trying to identify what input was pressed when i fired a server that read the press:

key.InputBegan:Connect(function(input)
	if input.KeyCode ~= Enum.KeyCode.Q then
		return
	end
	if key:IsKeyDown(Enum.KeyCode.A) or key:IsKeyDown(Enum.KeyCode.D) then
		events.Dash:FireServer()
	end
end)

This function fires the server when both Q and a or d is pressed

local events = game.ReplicatedStorage

events.Dash.OnServerEvent:Connect(function(player, direction)
	print(direction)
end)

This script connects to the fired server, but im not sure what argument to put so that it detects what key activated the press between a or d. This script right now just outputs nil whenever i activate the dash.

You’ve never inputed what the direction is on the client, so when retrieving the direction variable from the server, it will be nil

What argument would i have to put in fireserver() to read the input of the key pressing? or is it better to make if statements for every direction?

do something like this:

if key:IsKeyDown(Enum.KeyCode.A) then
	keyDown = "A"
	events.Dash:FireServer(keyDown)
	keyDown = ""
elseif key:IsKeyDown(Enum.KeyCode.D) then
	keyDown = "D"
	events.Dash:FireServer(keyDown)
	keyDown = ""
end
1 Like
events.Dash:FireServer(input.KeyCode.Name)

This will return the name of the key pressed. (“A” or “D”)

i tried this and it just gave me q probably because the input keycode is only used for q

yeah you should probably remove the first condition

Rewrite the second condition to something similar to this

if (key:IsKeyDown(Enum.KeyCode.A) or key:IsKeyDown(Enum.KeyCode.D)) and key:IsKeyDown(Enum.KeyCode.Q) then
	events.Dash:FireServer()
end

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