Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my remote event run, let alone the entire script?

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)
	

1 comment

0

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

1 answer

✓ Accepted 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

  1. The first parameter on the OnServerEvent event is the player who fired it. Also, I assume you were using "Print" as an argument.

  2. ServerScripts don't run on LocalScript's, or RemoteEvents. They only run on the following:

  • Workspace.

  • ServerScriptService

  • The upcoming ReplicatedScriptService

Solutions:

  1. Place the LocalScript in StarterPlayerScripts.

  2. Place the ServerScript in ServerScriptService.

  3. Place the RemoteEvent in ReplicatedStorage. Make sure the RemoteEvent is an actual RemoteEvent, not a RemoteFunction.

Recommendations:

  1. Use UserInputService as Mouse.KeyDown is deprecated.

  2. Put local before declaring a variable.

  3. 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

0

I cannot appreciate you enough. Thank you.

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.