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)
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:
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)
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
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.