Player = game.Players.LocalPlayer mouse = Player:GetMouse() Enabled = true mouse.Button1Down:connect(function() if Enabled == true then script.Function:FireServer("Print") print("1") end end) --2nd script script.Parent.OnServerEvent:Connect(function() print("2") end)
Hello.
Problem:
1.You must've put the LocalScript in the wrong spot. Local scripts can only run on the following:
StarterCharacterScripts
StarterPlayerScripts
PlayerGui
A player's character
ReplicatedFirst
The upcoming ReplicatedScriptService
The first parameter on the OnServerEvent
event is the player who fired it. Also, I assume you were using "Print" as an argument.
ServerScripts don't run on LocalScript's, or RemoteEvents. They only run on the following:
Workspace.
ServerScriptService
The upcoming ReplicatedScriptService
Solutions:
Place the LocalScript in StarterPlayerScripts.
Place the ServerScript in ServerScriptService.
Place the RemoteEvent in ReplicatedStorage. Make sure the RemoteEvent is an actual RemoteEvent, not a RemoteFunction.
Recommendations:
Use UserInputService
as Mouse.KeyDown
is deprecated.
Put local
before declaring a variable.
You do not need variables that you do not use. They waste memory.
Fixed Script:
local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then game.Replicated.RemoteEvent:FireServer("2") print("1") end end) --Server game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, message) print(message) end)
Please accept this answer if it helped!