Here's a Roblox Lua script that will unanchor all models in a specified table only when they are inside the player’s inventory (e.g., in Backpack or StarterGear). This is useful for ensuring items like tools, hats, or other models don't stay anchored when used by players.
✅ Features:
- Listens to when models from your predefined list enter a player's
Backpack or StarterGear.
- Unanchors all parts of the model recursively.
- Automatically handles multiple players and future additions to their inventory.
🧠 Assumptions:
- You have a table of models located in
ReplicatedStorage or another accessible folder.
- Each item in the table is a
Model.
🔧 Script: ServerScriptService
Place this in ServerScriptService:
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- The table containing your models
local ModelsToUnanchor = {
ReplicatedStorage.YourFolder.Model1,
ReplicatedStorage.YourFolder.Model2,
ReplicatedStorage.YourFolder.Model3
}
-- Function to unanchor all parts in an object
local function unanchorModel(model)
if model:IsA("Model") then
for _, part in ipairs(model:GetDescendants()) do
if part:IsA("BasePart") then
part.Anchored = false
end
end
end
end
-- Handle character spawn / backpack load
local function onPlayerAdded(player)
local function handleInventory(folder)
for _, child in ipairs(folder:GetChildren()) do
if child:IsA("Tool") or child:IsA("HopperBin") then continue end -- skip non-models like Tools
if typeof(child) == "Instance" and child:IsA("Model") then
if table.find(ModelsToUnanchor, child) then
unanchorModel(child)
end
end
end
-- Listen for new items added later (like via a shop system)
folder.ChildAdded:Connect(function(child)
if child:IsA("Tool") or child:IsA("HopperBin") then return end
if typeof(child) == "Instance" and child:IsA("Model") then
if table.find(ModelsToUnanchor, child) then
unanchorModel(child)
end
end
end)
end
player.CharacterAdded:Connect(function()
handleInventory(player.Backpack)
end)
handleInventory(player.StarterGear)
end
-- Connect to all existing and future players
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in ipairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
📁 How to Set Up:
- Place your models in a folder inside
ReplicatedStorage.
- Fill the
ModelsToUnanchor table with references to those models.
- Put this script in ServerScriptService.
💡 Notes:
- If your models are clones (e.g., cloned from templates), you may need to compare based on name instead of reference.
- If you're cloning models from storage into inventory, make sure to run the unanchor logic after the clone is placed in Backpack.
Let me know if you want a version that supports cloned models, or works with tools/hats/accessories specifically!