Whenever a player presses Q for example it shoots a projectile.

-LocalScript-

local Player = game.Players.LocalPlayer
UIS = game:GetService('UserInputService')
Mouse = Player:GetMouse()
RemoteFunction = game:GetService('ReplicatedStorage'):WaitForChild('Remotes'):WaitForChild('ProjectileRemote')


UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		RemoteFunction:FireServer()		
	end
end)
-ServerScript-

RemoteFunction = game:GetService('ReplicatedStorage'):WaitForChild('Remotes'):WaitForChild('ProjectileRemote')


RemoteFunction.OnServerInvoke = function(player)
	Mouse = player:GetMouse()
	a = instance.new('Part',workspace)
	b = instance.new('BodyVelocity',a)
	MouseAim = Mouse.Hit.p
	MousePosition = (Player.Character.Torso.CFrame *CFrame.new(0,0,10)).p
	a.CFrame = CFrame.new(MouseAim,MousePosition)
	b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	b.Velocity = a.CFrame.lookVector * 200

end

The code above gave me an error with 'Mouse' being a nil value.

Since I can't Get the players mouse in a server script, how can I send Mouse from the LocalScript to the ServerScript like this? (The Code Below is an explanation of what I mean isn't correct)

local Player = game.Players.LocalPlayer
UIS = game:GetService('UserInputService')
Mouse = Player:GetMouse()
RemoteFunction = game:GetService('ReplicatedStorage'):WaitForChild('Remotes'):WaitForChild('ProjectileRemote')


UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		RemoteFunction:FireServer(Mouse)		
	end
end)
-ServerScript-

RemoteFunction = game:GetService('ReplicatedStorage'):WaitForChild('Remotes'):WaitForChild('ProjectileRemote')


RemoteFunction.OnServerInvoke = function(player,Mouse)
	a = instance.new('Part',workspace)
	b = instance.new('BodyVelocity',a)
	MouseAim = Mouse.Hit.p
	MousePosition = (Player.Character.Torso.CFrame *CFrame.new(0,0,10)).p
	a.CFrame = CFrame.new(MouseAim,MousePosition)
	b.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	b.Velocity = a.CFrame.lookVector * 200

end

2 comments

1

You just send the mouse position or data to the server where it can be used, you cannot send the mouse instance.

0

And how would I do that? That's all I need basically.