Sending Mouse.Target through event to server, Server saying Mouse.Target nil?

Hey in my game I made a script that requires sending mouse.Target through an event - Local → Server.

Local Script;

Server Script;

The target is printing nil, and its causing and error in my script which needs the mouse.Target;


image

Thanks in advance, Mr. Monkey

It works fine for me. Can we see the local script?

Yeah,

The expanded “if” statement works fine I put a print there earlier to see if it worked.

it could print nil if ur hold ur cursor in the sky or if its a client sided part, try putting: if mousetarget ~= nil then --code end

In the Local script it prints the object that my mouse is pointing at, but I’ll try that anyway. Thanks

Now its just stopping, every shot is discontinuing the script. I already have a check that makes sure the target is glass. I think it might be a glitch, it’s just not getting the mouse.Target through the event? Is there a problem with the event/script?

it might be bc ur using a local when firing the server and not when ur printing it, there is a problem with motor6d if u make a local motor6d.C0 it wont work maybe this is a similar problem

Interesting, I’m going to hold my mouse there, and then look at output. If it doesnt work I’m going to remove the if and see if the “if” statement is messing it up.

So it turns out that it isnt on the glass, its on a part called “headBase” which I couldn’t find anywhere in the Explorer.

EDIT - Its calling everypart “headBase”

I’m not sure if this could be the reason, but one risk of passing object references through remote events is that both the client and the server must have access to the object. In this case, if you were to click an item that only exists locally, the server would print ‘nil’.

1 Like

How would I check if the item exists in both? When I switch client to server in test mode the building is there and so is the glass.

Well if the item you clicked exists on the server, then what I described is not the issue here.

However, note that you set an officebuilding as mouse.TargetFilter so that building would be ignored when clicking on it, and a target behind it would be chosen.

But you say you can’t find the name printed locally in explorer… I’m not sure what you mean there. In studio, when it happens, type the printed name in explorer, and do the same after pressing the ‘server’ button. If it exists on the client but not on the server, then that would be the problem.

So as it turns out Headbase is a part made by the gun that is blocking the glass target. It is made locally so the server can get it - explains nil. I however didnt know that target filter made it so that object was ignored - thanks for that. I thought it meant the object would be the only object mouse target could be in. So I need to switch the target filter to the Basehead parent, and then it should work.

1 Like

Hey it works!

Thanks for the help everyone! Happy Scripting!

1 Like