Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does it keep saying my mouse is nil when I already defined it? (Filtering Enabled)

Asked by
noposts 75
7 years ago
Edited 7 years ago

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

0
hm. It seems like your code is right... DropshipPilot 148 — 7y
0
did you tried on mouse write Mouse = game.player:GetMouse() HillsMaster 34 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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!

0
Well in the first place it works too when I press play, but when I use the server and client test (F7), it says that mouse is nil. But thanks for the tips noposts 75 — 7y
0
ah, gotcha. I'll see if I can keep running tests and find the elusive problem with you. DropshipPilot 148 — 7y
1
Changing the argument of FireServer() from just "mouse" to "mouse.Target" seemed to work. Thanks for the help! noposts 75 — 7y
0
I'm so glad you seem to have got it working! DropshipPilot 148 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

try this code on mouse local Mouse = Player:GetMouse()

0
sorry it's still nil noposts 75 — 7y

Answer this question