Helicopter Remote Event won't fire; why?

This script is a localscript/serverscript duo that, when a player clicks a particular area, will spawn a ray from the vehicle seat of the helicopter and act as a gun. The script doesn’t work, and I have to be honest, I have no idea why or how to make it work. Could someone help me?

---- serversided code
local mouse = Player:GetMouse()
local firing = script.Parent.VehicleSeat.firing --- code is inside helicopter

mouse.Button1Down:Connect(function()
	firing:FireServer(true,mouse)
end)

mouse.Button1Up:Connect(function()
	firing:FireServer(false,mouse)
end)

---server sided code, located in a script inside remote event
local firin = false

script.Parent.OnServerEvent:Connect(function(value,mouse)
	firin = true
	wait()
	while firin do 
	wait()
		if mouse.Target.Parent ~= script.Parent.Parent.Parent and mouse.Target.Parent.Parent ~= script.Parent.Parent.Parent then
			for i = 1, math.random(4,5) do
				--script.Parent.Parent.firing:Play()
				local theTar = mouse.Hit + Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5))
				local bull = Instance.new("Part")
				bull.Parent = game.Workspace
				bull.CFrame = CFrame.new((theTar + script.Parent.Parent.Position)/2,script.Parent.Parent.Position) --- script.Parent.Parent is the vehicle seat
				bull.CanCollide = false
				bull.BrickColor = BrickColor.new(24)
				bull.Anchored = true
				bull.Size = Vector3.new(1,1.2,1)
				game.Debris:AddItem(bull,0.1)
				local mesher = Instance.new("BlockMesh")
				mesher.Parent = bull
				mesher.Scale = Vector3.new(0.2, 0.2, (mouse.Hit - script.Parent.Parent.Position).magnitude)
				script.Cle:clone().Parent = bull
				local ex = Instance.new("Explosion")
				ex.BlastRadius = 5
				ex.BlastPressure = 5000
				ex.Position = theTar
				ex.Parent = game.Workspace
				wait(0.06)
			end
		end
	end
end)

Output always just says that I can’t use mouse in the serverside code since it’s a boolean; I’ve tried directly sending mouse.Target and mouse.Hit to it, but the issue just persisted since I couldn’t get the parent of mouse.Target.Parent.

The server cannot see the player’s mouse is created locally. Also it does not make sense for the server to handle user input.

2 Likes

What would the alternative be? Set a variable to each of the needed mouse properties (Target, Hit, etc.) in the LocalScript, and then pass it to the remote event?

And since something is being created (that being a projectile), I have to have it be server-sided at some point.

I would suggest just using Mouse.Hit for client side function since it is a Vector3.

The Mouse (itself) is a client side function, it is not compatible for RemoteEvent, also would be quite redundant if your just going to use Mouse.Hit as you can just use the Mouse.Hit in your client remote event and rename the mouse to mousePos for the server side. So your client script should be changed to this:

mouse.Button1Down:Connect(function()
	firing:FireServer(true,mouse.Hit)
end)

mouse.Button1Up:Connect(function()
	firing:FireServer(false,mouse.Hit)
end)

edit: Did not read your Mouse.Target, but you can add it next to the mouse.Hit with mouse.Target

mouse.Button1Down:Connect(function()
	firing:FireServer(true,mouse.Hit,mouse.Target)
end)

server side:

script.Parent.OnServerEvent:Connect(function(value,mouseHit,mouseTarget)

Remember that the player is implicitly passed as the first argument to FireServer.

1 Like