I enabled Filtering Enabled so I'm adding RemoteEvents and such.
I added a function in my local script so that when I click, it fires the server. I then added the mouse as an argument in the FireServer() function.
player = game.Players.LocalPlayer mouse = player:GetMouse() rep = game:GetService('ReplicatedStorage') reme = rep:WaitForChild('RemoteEvent') mouse.Button1Down:connect(function() reme:FireServer(mouse) end)
I wanted it to print "hello" when it clicks on the baseplate so I wrote this in the server script (The server script's name is "firer")
rep = game:GetService('ReplicatedStorage') reme = rep:WaitForChild('RemoteEvent') reme.OnServerEvent:connect(function(player, mouse) if mouse.Target == workspace.Baseplate then print 'hello' end end)
For whatever reason, it keeps on erroring and saying
15:11:09.355 - ServerScriptService.firer:5: attempt to index local 'mouse' (a nil value)
Sorry if my script doesn't make much sense and the mistake is obvious. This is one of my first times working with FE.
Edit since people say it works: It also works for me when I play, but when I use the client and server test (F7), it says mouse is nil
My script works as intended using your code! Everything should be right, seems it's just one of those things.
What I would recommend is revising your code to get rid of any unconventional or depreciated syntax. This includes capitalizing :Connect()
events, using game.Workspace
, and adding brackets to your print()
's.
Server Script:
rep = game:GetService('ReplicatedStorage') reme = rep:WaitForChild('RemoteEvent') reme.OnServerEvent:Connect(function(player, mouse) if mouse.Target == game.Workspace.Baseplate then print("hello") end end)
Local Script:
player = game.Players.LocalPlayer mouse = player:GetMouse() rep = game:GetService('ReplicatedStorage') reme = rep:WaitForChild('RemoteEvent') print(player.Name, mouse) mouse.Button1Down:Connect(function() reme:FireServer(mouse) end)
Remember, sometimes scripts can be finnicky. If all else fails, either add wait() commands after defining variables, or copy the code and re-enter it into a new script.
Good luck! Hope this helps!
try this code on mouse local Mouse = Player:GetMouse()