Help I'm trying to make an RC car game but I found a game breaking bug that caused the game to shut down, when you leave the game the car stays connected to nothing, which makes the car unusable. Is there a way to fix this?
local value = script.Parent.VehConnected
local tool = script.Parent
tool.Unequipped:Connect(function()
if value.Value ~= nil then
local FLmount = value.Value:FindFirstChild("FLWHEELMOUNT")
local FRmount = value.Value:FindFirstChild("FRWHEELMOUNT")
local RLmount = value.Value:FindFirstChild("RLWHEELMOUNT")
local RRmount = value.Value:FindFirstChild("RRWHEELMOUNT")
if FLmount ~= nil then
FLmount.CylFL.AngularVelocity = 0
end
if FRmount ~= nil then
FRmount.CylFR.AngularVelocity = 0
end
if RLmount ~= nil then
RLmount.CylRL.AngularVelocity = 0
end
if RRmount ~= nil then
RRmount.CylRR.AngularVelocity = 0
end
wait(0.1)
print("Remote unequipped with vehicle connected, disconnecting...")
value.Value.RemoteControlConnected.Value = false
wait(0.1)
value.Value = nil
tool.SignalReceive.Disabled = true
tool.Controllers:ClearAllChildren()
if tool.Parent.Name == "Backpack" then
local plr = tool.Parent.Parent.Name
local plrcharacter = game.Workspace:FindFirstChild(plr)
plrcharacter.Humanoid.JumpPower = 50
else
tool.Parent.Humanoid.JumpPower = 50
end
else
script.Parent.Handle.Part.Text.Value = ""
end
end)

2 comments
Try making it unequip whenever you leave the game?
I don't know howt o do that