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)
Why won't my remote event run, let alone the entire script?
1 answer
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
OnServerEventevent 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
UserInputServiceasMouse.KeyDownis deprecated.Put
localbefore 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!
2 comments
I cannot appreciate you enough. Thank you.
No problem.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
roblox is currently experiencing issues with scripts right now so that why and another reason could be because Player need to be set as a local