o4-mini-2025-04-16· OpenAI
LMArena Human Preference 140K
make me a script in roblox studio where all the models in a table will be unanchored…
- User
make me a script in roblox studio where all the models in a table will be unanchored when theyre in the players inventory
- Assistant
Here’s a simple ServerScript you can drop into ServerScriptService. It takes a Lua table of Models (already parented somewhere like ServerStorage), creates one Tool per model, and—whenever that Tool is moved into a player’s Backpack or Character—unanchors all BaseParts inside it.
-- ServerScriptService/UnanchorOnPickup.lua local ServerStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") -- 1) Put your Models into ServerStorage.Models (or adjust this path) local folderOfModels = ServerStorage:WaitForChild("Models") -- 2) Build a list (table) of those models local models = {} for _, model in ipairs(folderOfModels:GetChildren()) do if model:IsA("Model") then table.insert(models, model) end end -- 3) Helper: unanchor every BasePart in a Model/Tool local function unanchorAll(modelOrTool) for _, desc in ipairs(modelOrTool:GetDescendants()) do if desc:IsA("BasePart") then desc.Anchored = false end end end -- 4) For each model, create a Tool that carries it for _, model in ipairs(models) do -- Clone the model so original stays in Storage local mdlClone = model:Clone() -- Create the Tool local tool = Instance.new("Tool") tool.Name = model.Name tool.RequiresHandle = false tool.CanBeDropped = true -- parent the cloned model under the Tool mdlClone.Parent = tool -- Watch for the Tool moving into a Backpack or Character tool.AncestryChanged:Connect(function(child, newParent) if newParent then -- if parent is a Backpack if newParent:IsA("Backpack") -- or parent is a Character model (with a Humanoid) or (newParent:IsA("Model") and newParent:FindFirstChildOfClass("Humanoid")) then unanchorAll(tool) end end end) -- Finally, store the Tool in ServerStorage.Tools -- (so it doesn’t clutter the Workspace until given to a player) local toolsFolder = ServerStorage:FindFirstChild("Tools") or Instance.new("Folder", ServerStorage) toolsFolder.Name = "Tools" tool.Parent = toolsFolder end -- 5) Give each player all the tools on spawn Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) -- wait for Backpack to exist local backpack = player:WaitForChild("Backpack") local toolsFolder = ServerStorage:WaitForChild("Tools") for _, tool in ipairs(toolsFolder:GetChildren()) do tool:Clone().Parent = backpack end end) end)How it works step by step:
- You store all your Models under
ServerStorage.Models. - The script loops through them, clones each, and wraps it in a new
Tool. - Whenever that Tool is parented into someone’s
BackpackorCharacter(i.e. “in the inventory”), it firesAncestryChanged. - We respond by unanchoring every
BasePartin the tool so it can be physically manipulated. - On player join, we clone all these tools into their Backpack.
Feel free to adapt:
• Change where you keep your original Models.
• Alter who and when you give out Tools.
• Add cooldowns, GUI buttons or equip/unequip logic for more control.Happy building! 🎮
- You store all your Models under
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.