I was fooling around earlier today with tools and I realized that even if you destroy a tool the code after the :Destroy() command will still run and I was honestly just curious as to how this is possible if the script no longer exists? I forcefully unequip the tool and then when it gets placed inside the backpack I destroy the tool and yet the code below the :Destroy() line continues to run even know the script no longer exists.
This is an example of some code I have that runs after the module script gets requested. The script that requests the module script is also a part of the tool. The while loop continues to print even after the script no longer exists.
function Module.Fire()
local Character = Tool:FindFirstAncestorWhichIsA("Model")
local Player = Players:GetPlayerFromCharacter(Character)
ClientInputEvent.OnServerEvent:Connect(function()
local HuntImmunity = Instance.new("BoolValue")
HuntImmunity.Name = "HuntImmunity"
HuntImmunity.Parent = Character
for Index, Object in ipairs(Data[Player.UserId].TemporaryData:GetChildren()) do
if string.find(Object.Name, "Tool") ~= nil and Object.Value == Tool.Name then
Object.Value = ""
end
end
Character.Humanoid:UnequipTools()
Player.Backpack:FindFirstChildWhichIsA("Tool"):Destroy()
while true do
print(1)
end
end)
end
If anyone could help me to understand how this works I would be really thankful. Thanks and have a good one!