Hello! Currently in the process of making a script with key binds, and I planned on using remote events to take the user’s key input (UserInputService) and fire an event to the server, carrying the script from there. The local script firing the event does fire, but the server script does not respond at all. Plus, there’s no errors inside the output.
Local Script:
local eventsFolder = script.Parent:WaitForChild("events")
UserInputService.InputBegan:Connect(function(input,gameProcessed)
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.Z then
eventsFolder:WaitForChild("zKey"):FireServer(playerMouse.Hit.Position)
print("Z Key fired")
end
end
end)
Server Script:
local eventsFolder = script:WaitForChild("events")
eventsFolder.zKey.OnServerEvent:Connect(function(plr,mousePos)
print("Received")
stairCaseUp(plr,mousePos) -- I've tested the function, and it works on it's own
print("Successfully fired function")
end)
Output:
Z Key fired
I’ve tried moving the remote events folder (“eventsFolder”) to ReplicatedStorage, and the server script into ServerScriptService (originally in the player’s character). I don’t know what I’m doing wrong.
Okay so parenting the mainScript in the player’s character should be fine. Nothing to be concerned about here.
However, I am confused by the output. There is no “Z key fired” print in both of your scripts.
Place a breakpoint here (if you don’t know how to, just place a print just above) and tell me if that breakpoint or print is being triggered.
My bad, forgot to put the print in the original edit. The “Z Key fired” came from the local script, below the FireServer(). Nothing changes, and it still isn’t functional.
local eventsFolder = script:WaitForChild("events")
print("Connecting to the event " .. eventsFolder.zKey.Name) --This will determine wether the script is running and if eventsFolder.zKey is not detected as nil by the server
eventsFolder.zKey.OnServerEvent:Connect(function(plr,mousePos)
print("Received")
stairCaseUp(plr,mousePos) -- I've tested the function, and it works on it's own
print("Successfully fired function")
end)
Is there anything else in the output? Have you tried putting a print in the server script to make sure it’s actually running? Like this;
print("Getting events")
local eventsFolder = script:WaitForChild("events")
print("Found events!")
eventsFolder.zKey.OnServerEvent:Connect(function(plr,mousePos)
print("Received")
stairCaseUp(plr,mousePos) -- I've tested the function, and it works on it's own
print("Successfully fired function")
end)
Alright, so I’ve tried both Liyud and Phoenix’s suggestions, still didn’t work. However, I did get the script to finally work by moving a “while true do” script I had laying around to the end of the server script. (Whoops!)
Anyways, marking this as solved, tysm for the assistance!