Fireserver not sending any information

Hi,

I am trying to make a Fireserver event work by sending information to the server side.
However, for unknown reasons this does not work, I’ve tried looking around for solutions but they were similar to my script for they worked. So I have no Idea why it shouldn’t. I’ve checked everything if they’re correct and they are.

Local

local UIS = game:GetService("UserInputService")
local event = script.Parent:WaitForChild("RemoteEvent")


UIS.InputBegan:Connect(function(k)
	if k == Enum.KeyCode.A then
		event:FireServer("lefton")
	end
end)

UIS.InputEnded:Connect(function(k)
	if k == Enum.KeyCode.A then
		event:FireServer("leftoff")
	end
end)

UIS.InputBegan:Connect(function(k)
	if k == Enum.KeyCode.D then
		event:FireServer("righton")
	end
end)

UIS.InputEnded:Connect(function(k)
	if k == Enum.KeyCode.D then
		event:FireServer("rightoff")
	end
end)

Server

local leftb = script.Parent.Left
local rightb = script.Parent.Right
local server = script.Parent:WaitForChild("RemoteEvent")

leftb.MouseButton1Down:Connect(function()
	script.Parent.L.Value = true
end)

leftb.MouseButton1Up:Connect(function()
	script.Parent.L.Value = false
end)

rightb.MouseButton1Down:Connect(function()
	script.Parent.R.Value = true
end)

rightb.MouseButton1Up:Connect(function()
	script.Parent.R.Value = false
end)

server.OnServerEvent:Connect(function(info)
	if info == "lefton" then
		script.Parent.L.Value = true
	end
end)


server.OnServerEvent:Connect(function(info)
	if info == "leftoff" then
		script.Parent.L.Value = false
	end
end)

server.OnServerEvent:Connect(function(info)
	if info == "righton" then
		script.Parent.R.Value = true
	end
end)


server.OnServerEvent:Connect(function(info)
	if info == "rightoff" then
		script.Parent.R.Value = false
	end
end)

Any help would be appriciated.

I believe the issue is the if statements, such as

if k == Enum.KeyCode.A then

The parameter k is of the form InputObject, so you can’t immediately compare it to a keycode. Instead, you should access the keycode property of it:

if k.KeyCode == Enum.KeyCode.A then

edit: As Ethan also brought up - The first parameter of OnServerEvent will always be the player who called it, so you will need to adjust accordingly for that too.

On the OnServerEvent function the first variable is always going to be player, try changing the functions to: server.OnServerEvent:Connect(function(player, info). Will also need to do what @SeargentAUS says with the keycodes.

1 Like

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