I have a tool that shoots a laser when the Activated event is called. As the laser in question has to have multiple static properties set (color, material, collisions, etc.), I figured it would be better to create it once and re-parent it accordingly:
--Bare-bones version of my script:
local tool = script.Parent
local laser = Instance.new("Part")
tool.Activated:Connect(function()
laser.Parent = tool
end)
local function stopShooting()
laser.Parent = nil
end
tool.Deactivated:Connect(stopShooting)
tool.Unequipped:Connect(stopShooting)
There are no event connections or references to the laser outside of this script. What I want to know is, if the player dies and respawns while the laser is parented to nil, will it cause a memory leak? All tools in the player’s backpack would be destroyed in the process of respawning and would therefore destroy the only reference to the laser–but as the laser is parented to nil, would it continue to stay in memory regardless?