I have a LocalScript in StarterGui that detects if the player presses F4. If the player does, it will fire a BindableEvent in ReplicatedStorage, called F4Pressed, which then executes code inside of a server script to mess with some GUIs.
Here's my problem: the server never seems to get any response. There is a print statement in the LocalScript that fires when I press F4, but the server never seems to recognize that the BindableEvent fired.
LocalScript:
player = game.Players.LocalPlayer mouse = player:GetMouse() function PressedE(key) if key:byte() == 29 and game.ReplicatedStorage.Game.Value == false then print(player.Name.." pressed F4.") -- this print statement goes through just fine game.ReplicatedStorage.F4Pressed:Fire(player.UserId) end end mouse.KeyDown:connect(PressedE)
Server Script (snippet):
game.ReplicatedStorage.F4Pressed.Event:connect(function(playerId) print("Hello!") -- never fires end)
BindableEvents don't go across the network.
You need to use RemoteEvents in order to talk between LocalScripts and Scripts.
The code will be almost the same, with a few adjustments:
:FireServer
instead of :Fire
OnServerEvent
instead of Event
player
object as the first parameter, so you don't need to pass player.UserId
(since player
will be passed automatically) -- instead, the server script can simply inspect player.UserId
, where player
is its first parameter (instead of playerId
)