I have this code:
local mainServer = script.Parent.MainServer local accFwdEvent = mainServer.accelerateForward local accBwdEvent = mainServer.accelerateBackward local player = game.Players.LocalPlayer -- Get player local mouse = player:GetMouse() -- Get mouse local function accelForward() accFwdEvent:FireServer(true, 1) print("Sent!") end local function accelBackward() accBwdEvent:FireServer(false, 1) end game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.W then accelForward() end end)
I am pressing W, but I don't see the "Sent!" I should. My RemoteEvents and everything is set up properly. I've tried all ways I've seen. NOTHING works. This is in a localscript. Please help.
Your remote events and server script most likely aren't running in the right places. It seems to be looking like you've parented your serverScript and your remoteEvents together, and they seem to be running on the client.
--local script Here's what your hierarchy should look like: local replicatedStorage = game:GetService("ReplicatedStorage") local accFwdEvent = replicatedStorage.accFwd local accBwdEvent = replicatedStorage.accBwd local player = game.Players.LocalPlayer -- Get player local mouse = player:GetMouse() -- Get mouse local function accelForward() accFwdEvent:FireServer(true, 1) print("Sent!") end local function accelBackward() accBwdEvent:FireServer(false, 1) end game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.W then accelForward() end end)
We use replicatedStorage because the client and the server can both "see" them/have access to them.
--server script, assuming this is your "mainServer" local replicatedStorage = game:GetService("ReplicatedStorage") local accFwdEvent = replicatedStorage.accFwd local accBwdEvent = replicatedStorage.accBwd local function printIfConnected() print("hey you got it right now") end accFwdEvent.OnServerEvent:Connect(printIfConnected)