So, I tried to make a GUI game, and this error occurred: Remote event not firing:
here the local script:
local UIS = game:GetService(“UserInputService”)
local Remote = game.ReplicatedStorage:WaitForChild(“ArrowBind”)
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType.Name == "Keyboard" and processed == false then
if input.KeyCode.Name == Enum.KeyCode.Up then
Remote:FireServer(1)
elseif input.KeyCode.Name == Enum.KeyCode.Right then
Remote:FireServer(2)
elseif input.KeyCode.Name == Enum.KeyCode.Down then
Remote:FireServer(3)
elseif input.KeyCode.Name == Enum.KeyCode.Left then
Remote:FireServer(4)
end
end
end)
and heres the server script:
local Event = game.ReplicatedStorage:WaitForChild(“ArrowBind”)
In your local script you only are firing a number but in your sever script where you are getting the event you are trying to get player and arrow from it. Both of which are not variables that where sent. TO fix it:
you need to have a variable that defines player and arrow in your local script.
Remote:FireSever(player, arrow, 4)
The first parameter is automatic so you would not need to pass the player and the number that he is giving would be the arrow. I think the problem here is that you wrote
when it should be if input.UserInputType == "Keyboard and processed == false then
you also wrote .Name for the nested if statements
local UIS = game:GetService("UserInputService")
local Remote = game.ReplicatedStorage:WaitForChild("ArrowBind")
local player = game.Players.LocalPlayer
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType.Name == "Keyboard" and processed == false then
print("m")
if input.KeyCode.Name == Enum.KeyCode.Up then
local Arrow = 1
Remote:FireServer(player, Arrow, 1)
elseif input.KeyCode.Name == Enum.KeyCode.Right then
local Arrow = 2
Remote:FireServer(player, Arrow, 2)
elseif input.KeyCode.Name == Enum.KeyCode.Down then
local Arrow = 3
Remote:FireServer(player, Arrow, 3)
elseif input.KeyCode.Name == Enum.KeyCode.Left then
local Arrow = 4
Remote:FireServer(player, Arrow, 4)
end
end
end)
You don’t need to use .Name on input.KeyCode, also there’s an Enum for UserInputType.
Here’s the fixed code:.
local UIS = game:GetService("UserInputService")
local Remote = game.ReplicatedStorage:WaitForChild("ArrowBind")
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.Keyboard and not processed then
print("m")
if input.KeyCode == Enum.KeyCode.Up then
Remote:FireServer(1)
elseif input.KeyCode == Enum.KeyCode.Right then
Remote:FireServer(2)
elseif input.KeyCode == Enum.KeyCode.Down then
Remote:FireServer(3)
elseif input.KeyCode == Enum.KeyCode.Left then
Remote:FireServer(4)
end
end
end)
Edit: You don’t need to send the player, the first parameter of a Remote Event fired from a Client is the player who fired it.
This means that either your server script is in the player or the local script is on the server.
try putting your local script inside StarterGui and the server script inside ServerScriptService
That is probably the main issue but i changed some things that in your scripts too.
Local script:
local UIS = game:GetService("UserInputService")
local Remote = game.ReplicatedStorage:WaitForChild("ArrowBind")
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if not processed then
print("KeyDown")
if input.KeyCode == Enum.KeyCode.Up then
Remote:FireServer(1)
elseif input.KeyCode == Enum.KeyCode.Right then
Remote:FireServer(2)
elseif input.KeyCode == Enum.KeyCode.Down then
Remote:FireServer(3)
elseif input.KeyCode == Enum.KeyCode.Left then
Remote:FireServer(4)
end
end
end
end)
You don’t need to send the player when firing remote events, the first parameter of the OnServerEvent function will always be the player, the second parameter will be the first argument you sent to the function, third will be the second, and so on…
“Remote not firing” is not specific enough an error to determine what your problem is. Your code as posted in the OP is fine, so obviously there’s another underlying issue that’s being overlooked here. Please provide the exact error you’re encountering or a hierarchy of your objects for further help debugging.
Did you ever try changing the parent? Local scripts can only run in certain places on the client like StarterPlayerScripts and server scripts can only run on the server, like ServerScriptService.
The script looks fine to me. Is that the full script? Is there a loop of any kind before that snippet?
Also if you’re firing the remote to change something on the client, ex under PlayerGui, you should change that in the local script since the server wouldn’t be able to access the player’s guis as far as I know.
As colbert said, it would really help if you showed a picture of where your scripts are located.
Perhaps you’re listening for the wrong remote event, maybe that’s not the wanted remote event to use .OnServerEvent on
This might even be a connection problem