I was wondering what seems to be the problem with my code here?
when you subtract mousepos from origin, mousepos is not guaranteed to exist. If you point your mouse into the air (the target is null), then the mousepos will also be null. This is what the compiler means by “attempt to subtract null from vector3” - mousepos is null. To resolve this, you can just add a check to verify that mousepos is not null, like if mousepos then ... end
How would I add that onto what I already have?
Add that on like this:
remote.OnServerEvent:Connect(function(player, mousepos)
if mousepos then
local orgin = tool.Handle.GunFirePoint.WorldPosition
local direction = (mousepos-orgin).Unit
local caster = fastcast.new()
local behaviour = caster.newBehavior()
behavior.RaycastParams = params
caster:Fire(orgin, direction, 250, behaviour)
end
end)
If that were the case, he should be getting a different error: Attempt to index nil with Position
mouse.Hit works even on the skybox and that is likely what he is using.
@Refined_Gaming1 where do you fire the RemoteEvent?
The remote event is fired inside the gun (tool)
Can I see the code that gets the mouse input and fires the event?
Change that line in the top script to this.
remote:FireServer(mouse.Hit.p)
I need to go, good luck getting all of the wrinkles ironed out.