Mouse.Hit is no longer active error

Hello. I’m working on a rocket launcher and when I go to shoot it, an error message pops up saying “This Mouse is no longer active”. I don’t know how to fix this or what’s causing this. below is a piece of the launchers script:

Tool.Activated:Connect(function()
	if Tool.Enabled == true then
		Tool.Enabled = false
		local SpawnPosition = (Tool.Handle.CFrame * CFrame.new(3, 0, 0)).p
		local VelocityCFrame = CFrame.lookAt(SpawnPosition, PlayerMouse.Hit.p) --Brakes here
		
		local FiredRocket = Rocket:Clone()		--Setup rocket
		FiredRocket.CFrame = VelocityCFrame 
		FiredRocket.Position = SpawnPosition
		FiredRocket.Velocity = VelocityCFrame.LookVector * 60
		FiredRocket.Parent = game.Workspace
		
		game:GetService("Debris"):AddItem(FiredRocket, 10)
		wait(3)
		Tool.Enabled = true
	end
end)

I hope this helps. thank you for reading.

1 Like

Hello!

Try setting the mouse variable to a new mouse on activated, I assume roblox is making that old mouse inactive which is what’s throwing you that error.

Like this;

Tool.Activated:Connect(function()
	if Tool.Enabled == true then
        PlayerMouse = Player:GetMouse() --> if there is a player variable
		Tool.Enabled = false
		local SpawnPosition = (Tool.Handle.CFrame * CFrame.new(3, 0, 0)).p
		local VelocityCFrame = CFrame.lookAt(SpawnPosition, PlayerMouse.Hit.p) --Brakes here
		
		local FiredRocket = Rocket:Clone()		--Setup rocket
		FiredRocket.CFrame = VelocityCFrame 
		FiredRocket.Position = SpawnPosition
		FiredRocket.Velocity = VelocityCFrame.LookVector * 60
		FiredRocket.Parent = game.Workspace
		
		game:GetService("Debris"):AddItem(FiredRocket, 10)
		wait(3)
		Tool.Enabled = true
	end
end)

Player:GetMouse() only works in LocalScript's.

The only possible instance I could really make out of this is that Tool.Enabled also prevents the Mouse from being interacted with, although I’m unsure if that would be the case since this is the only known information about Tool.Enabled:

You could try creating a Bool variable to see if that makes any difference, otherwise I’d check to look and see where & when you’re getting the Mouse

This was happening even before I started messing with Tool.Enabled, so I don’t think that’s the issue. Even when it’s set to false, Tool.Activated still fires.

Is that the entire script of it? The script would be working fine on it’s own, unless if you’re something a deprecated object of some sort that’s preventing your script from running preferably in this line here:

Maybe try this

Tool.Activated:Connect(function()
	if Tool.Enabled == true and Mouse.Hit then
		Tool.Enabled = false

        local CurrentPos = Mouse.Hit.Position
		local SpawnPosition = (Tool.Handle.CFrame * CFrame.new(3, 0, 0)).p
		local VelocityCFrame = CFrame.lookAt(SpawnPosition, CurrentPos) --Brakes here
		
		local FiredRocket = Rocket:Clone()		--Setup rocket
		FiredRocket.CFrame = VelocityCFrame 
		FiredRocket.Position = SpawnPosition
		FiredRocket.Velocity = VelocityCFrame.LookVector * 60
		FiredRocket.Parent = game.Workspace
		
		game:GetService("Debris"):AddItem(FiredRocket, 10)
		wait(3)
		Tool.Enabled = true
	end
end)

Mouse.Hit is the position value
https://developer.roblox.com/en-us/api-reference/property/Mouse/Hit

Isn’t it being referenced in the ServerScript here?

local VelocityCFrame = CFrame.lookAt(SpawnPosition, PlayerMouse.Hit.p)

I recommend using an RemoteEvent to fire the Rocket so the server can get the mouse position from the client.

Here’s an example;

-- Client side
local PlayerService = game:GetService("PlayerService")

local Tool = Script.Parent
local Player = PlayerService.LocalPlayer
local PlayerMouse = nil
local FireRocketEvent = Tool:WaitForChild("RemoteEvent")

Tool.Activated:Connect(function()
	if Tool.Enabled == true then
        PlayerMouse = Player:GetMouse() 
		Tool.Enabled = false
		FireRocketEvent:FireServer(PlayerMouse.Hit.p)
		wait(3)
		Tool.Enabled = true
	end
end)
-- Server side
local Tool = Script.Parent
local FireRocketEvent = Tool:WaitForChild("RemoteEvent")
local ServerDebounce = false --> I also recommend these for safety measures
local Rocket = -- ?

FireRocketEvent.OnServerEvent:Connect(function(Player, Pos)
    if not (ServerDebounce) and (Tool:IsDescendantOf(Player.Character)) then -- Safety measures
		ServerDebounce = true
		
		local SpawnPosition = (Tool.Handle.CFrame * CFrame.new(3, 0, 0)).p
		local VelocityCFrame = CFrame.lookAt(SpawnPosition, Pos)
		
		local FiredRocket = Rocket:Clone()		--Setup rocket
		FiredRocket.CFrame = VelocityCFrame 
		FiredRocket.Position = SpawnPosition
		FiredRocket.Velocity = VelocityCFrame.LookVector * 60
		FiredRocket.Parent = game.Workspace
		
		game:GetService("Debris"):AddItem(FiredRocket, 10)
		
		task.wait(3)
		ServerDebounce = false
    end
end)

If this is handled in a ServerScript, you still need the client to form data about where their mouse is, so using a RemoteEvent are the way to go.

You can check out all the sick things about Remote Instances here and information about the client-server model used for the engine here

1 Like

No? Mouse.Hit alone is a CFrame Value, but Mouse.Hit.Position is what’s known as a Vector3 Value

Also a couple minor thing I noticed, but p is deprecated and should be replaced with Position instead

1 Like

To be honest, I wanted to avoid using RemoteEvents and keep things in one Script. However, I think it would be better to use a RemoteFunction to return PlayerMouse.Hit.p from the LocalScript to the ServerScript.

This is definitely a way to do it. Although, the mouse is only accessible on the client and you would still need two scripts (client and server) to manage the weapon.

How about this?

Tool.Equipped:Connect(function(mouse)
   -- your stuff here
end)

That’s what I’ve been using, which is why I’ve been having this problem.