I’m trying to make a rocket launcher. I realized that after a while of using and dying, the position which the rockets point to starts to get delayed. This weapon is supposed to have a fairly long cooldown so this is going to be a bad problem.
This is the local script for giving the mouse position:
local me = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local camera = game.Workspace.CurrentCamera
local get = game.ReplicatedStorage["mouse position stuff"]["get mouse position"]
local give = game.ReplicatedStorage["mouse position stuff"]["give mouse position"]
get.OnClientEvent:Connect(function()
local position = mouse.Hit.Position -- I USE A VARIABLE SO I CAN TRY OUT DIFFERENT METHODS
give:FireServer(position) -- GIVE THE SERVER THE MOUSE POSITION
end)
Here is the server script for running the whole rocket launcher:
local me = script.Parent
local handle = me.Handle
local rocket = game.ServerStorage["launcher stuff"]["launcher rocket"]
local get = game.ReplicatedStorage["mouse position stuff"]["get mouse position"]
local give = game.ReplicatedStorage["mouse position stuff"]["give mouse position"]
local debris = game:GetService("Debris")
me.Activated:Connect(function()
local char = me.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
get:FireClient(plr) -- KINDLY ASK THE PLAYER FOR THE MOUSE POSITION
local player, position = give.OnServerEvent:Wait() -- RECEIVE THE MOUSE POSITION QUICKLY
handle["Rocket Launcher Fire"]:Play() -- SOUNDS FOR THE LAUNCHER
local clone = rocket:Clone() -- CLONE THE STORED MESH
clone.Parent = game.Workspace
clone.CFrame = handle.CFrame
clone.CFrame = CFrame.lookAt(clone.Position, position)
clone.CFrame = clone.CFrame * CFrame.new(0, 0, -10)
debris:AddItem(clone, 10) -- FOR OPTIMIZATION, HAVE THE ROCKET DESPAWN AFTER 10 SECONDS.
end)
In the video, the rocket launcher starts to become inaccurate after a few deaths.