For some reason when I use the regen feature on my jet after it gets destroyed, it turns to where the old mouse hit position was and then doesn’t work at all after that. I found out that for some reason the jet is getting information from the remote event without the client firing to the server. The reason why the jet can’t move past that is that for some reason the system that allows the client to get the ID of the jet stops working after the jet is regenerated
The system mainly works by taking inputs from the client script, sending them over a remote event with a unique ID that every jet gets when it spawns in, and then the serverside script checks the ID to make sure it’s the right ID, and then does the action relating to the input and a couple of variables.
Main Jet Code
wait(1.5)
local rs = game:GetService("RunService")
local minspeed = 0
local maxspeed = 10
local acceleration = .1
local ShipID = script.Parent.ShipID.Value
local speed = 0
local re = game.ReplicatedStorage.Events.ShipInput
local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(0.8, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local airborne = false
local mouseheld = false
local lookpos = nil
local wheld = false
local sheld = false
local function tweenModel(model, CF) --Made by ImagineerColbert
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, info, {Value = CF})
repeat
tween:Play()
wait()
tween:Pause()
script.Parent:pivotTo(script.Parent.PrimaryPart.CFrame + (script.Parent.PrimaryPart.CFrame.LookVector * speed))
until tween.Completed
tween.Completed:Connect(function()
CFrameValue:Destroy()
end)
end
re.OnServerEvent:Connect(function(plr, input, ID, var1, var2)
if ID == ShipID then
if input == Enum.UserInputType.MouseButton1 then
if var2 == true then
lookpos = var1
mouseheld = true
else
info = TweenInfo.new(0.8, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
lookpos = nil
mouseheld = false
end
end
if input == Enum.KeyCode.W then
if var2 == true then
wheld = true
else
wheld = false
end
end
if input == Enum.KeyCode.S then
if var2 == true then
sheld = true
else
sheld = false
end
end
end
end)
rs.Heartbeat:Connect(function()
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {script.Parent}
local raycast = game.Workspace:Raycast(script.Parent.PrimaryPart.Position, Vector3.new(0, -20, 0), rayParams)
if raycast then
airborne = false
else
airborne = true
end
script.Parent:pivotTo(script.Parent.PrimaryPart.CFrame + (script.Parent.PrimaryPart.CFrame.LookVector * speed))
if speed >= maxspeed then
speed = maxspeed
else if speed <= minspeed then
speed = minspeed
end
end
if wheld == true then
speed = speed + acceleration
end
if sheld == true and speed ~= minspeed then
speed = speed - acceleration
end
if mouseheld == true then
tweenModel(script.Parent, CFrame.lookAt(script.Parent.PrimaryPart.Position, lookpos.Position))
info = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
end
if airborne == true and script.Parent.Parts.Seat.Occupant ~= nil then
local hitboxParams = OverlapParams.new()
hitboxParams.FilterType = Enum.RaycastFilterType.Exclude
hitboxParams.FilterDescendantsInstances = {script.Parent}
for i, v in pairs(game.Workspace:GetPartsInPart(script.Parent.Hull.LeftBodyMain, hitboxParams)) do
if not v:IsDescendantOf(script.Parent.Parts.Seat.Occupant.Parent) then
local explosion = Instance.new("Explosion")
explosion.Parent = game.Workspace
explosion.Position = script.Parent.PrimaryPart.Position
explosion.BlastRadius = 100
re:FireClient(game.Players:GetPlayerFromCharacter(script.Parent.Parts.Seat.Occupant.Parent), "crashed")
script.Parent:Destroy()
break
end
end
end
end)
Main Client Script
local rs = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
wait(1)
local ID = nil
local held = false
local injet = false
local gseat = nil
local re = game.ReplicatedStorage.Events.ShipInput
re.OnClientEvent:Connect(function(var1)
if var1 == "crashed" then
re:FireServer(Enum.UserInputType.MouseButton1, nil, nil, false)
end
end)
re:FireServer(Enum.UserInputType.MouseButton1, ID, nil, true)
char.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
if char.Humanoid.Sit == false then
re:FireServer(Enum.UserInputType.MouseButton1, nil, nil, false)
gseat = nil
ID = nil
injet = false
end
end)
char.Humanoid.Seated:Connect(function(seated, seat)
if seated then
if seat.Parent.Parent.ShipID then
gseat = seat
injet = true
ID = seat.Parent.Parent.ShipID.Value
end
end
end)
UIS.InputBegan:Connect(function(input)
if char.Humanoid.Seated then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
held = true
local pos = plr:GetMouse().Hit
re:FireServer(input.UserInputType, ID, pos, held)
end
if input.KeyCode == Enum.KeyCode.W then
re:FireServer(input.KeyCode, ID, 1, true)
end
if input.KeyCode == Enum.KeyCode.S then
re:FireServer(input.KeyCode, ID, 1, true)
end
end
end)
UIS.InputEnded:Connect(function(input)
if char.Humanoid.Seated then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
held = false
local pos = plr:GetMouse().Hit
re:FireServer(input.UserInputType, ID, nil, held)
end
if input.KeyCode == Enum.KeyCode.W then
re:FireServer(input.KeyCode, ID, nil, false)
end
if input.KeyCode == Enum.KeyCode.S then
re:FireServer(input.KeyCode, ID, nil, false)
end
end
end)
rs.RenderStepped:Connect(function()
if held == true and injet == true and char.Humanoid.Health >= 1 then
plr:GetMouse().TargetFilter = gseat.Parent.Parent
local pos = plr:GetMouse().Hit
re:FireServer(Enum.UserInputType.MouseButton1, ID, pos, true)
end
if injet == true then
game.Workspace.CurrentCamera.CFrame = gseat.Parent.Parent.Camera.CFrame
end
end)
Regen Button
--FIGURE OUT HOW TO EXORCISE RESPAWNED JETS
local ready = true
local vehicle = game.ReplicatedStorage.Vehicles["R-17 Wraith"]:Clone()
script.Parent.Triggered:Connect(function(plr)
if ready == true then
if vehicle.Parent == nil then
vehicle = game.ReplicatedStorage.Vehicles["R-17 Wraith"]:Clone()
end
if vehicle.Parts.Seat.Occupant == nil then
vehicle:PivotTo(script.Parent.Parent.Parent.RegenPos.CFrame)
vehicle.Parent = game.Workspace
for i, v in pairs(script.Parent.Parent.Parent.Ghost:GetDescendants()) do
v.Transparency = 1
end
ready = false
wait(5)
ready = true
for i, v in pairs(script.Parent.Parent.Parent.Ghost:GetDescendants()) do
v.Transparency = 0.5
end
end
end
end)
ID setting script
wait(1)
script.Parent.Value = (script.Parent.Parent.PrimaryPart.Position.X*script.Parent.Parent.PrimaryPart.Position.Z+script.Parent.Parent.PrimaryPart.Position.Y)