It’s ok, take a deep breath. I told you that I’d tell you how, so I’ll go ahead and do that:
- In the outliner to, press on the “World” Instance
- On the top of the screen, press “Part”. A new part should spawn in the World
- In the outliner tab or in the “Viewport” tab, find and click on your newly created part
- Open the “Properties” tab and scroll down to the bottom of the options.
- You should see a button called “Add Components”. Click on it
- Find the “Tool” component using either the search bar or by manually scrolling to the “Custom” header. Click on it
- This item should now be eligible for being equipped. Now we need to make it spawnable by scripts. Using steps 4-6, add a new “PrefabInstance” component
- In the properties tab, find the Prefab instance component you just made and set its “PrefabId” field to any random number you want (that isn’t too big)
- In the Outliner Tab, select the part and change its name to something memorable by clicking on it twice
- While making sure the part is still selected in the Outliner tab, go to file → Export Model on the top left part of the window
- Save the part to the root of the “prefabs” folder in your project. You don’t need to nest it because Luduvo will take care of that automatically
- Back in Studio, open the “assets” tab next to the “Output” tab
- Navigate to the place you just saved as a model, and in that directory, find the folder with the same name as your recently exported part.
- Right click on
asset.json, and select the “Import as Asset” option in the dropdown - Create a new part following steps 1-4
- Instead of pressing “Add Components”, press the “Attach Script” button.
- Press “New Blank Script”, then change the radio button to “Server” before finalizing the new script
- Open your file explorer and navigate to where you have your project stored pressing “open in editor” will currently crash Luduvo
- In your project, go to the “scripts” folder, and find the script that you just made to attach to the part. When prompted how to open, use your text editor of choice (even notepad is ok for now)
- If you have your own external IDE or code editor, look into adding Luduvo LSP
- Paste the following into the file to get you started, replacing “Yourtoolnamehere” with the name of the part you exported:
local players = {} -- Stores all the players in the game
local given = {} -- Stores whether a player has our custom tool in their hotbar or not
game.Players.PlayerJoined:Connect(function(playerInst)
-- Saving the player's Instance when they join instead of querying for them every frame will save us a good bit of compute/time
players[playerInst] = true
end)
game.Players.PlayerLeft:Connect(function(character, playerInst)
-- When a player leaves that game... they obviously aren't going to have the tool anymore so we need to update our cache
players[playerInst] = nil
given[playerInst] = nil
end)
game.Players.CharacterDied:Connect(function(character, playerInst, attach)
given[playerInst] = nil -- Players lose their entire hotbar when they die, so its no longer "given" anymore
end)
local tool = game.Prefabs.Id("Yourtoolnamehere") -- Gets the ID of the tool you just made
function Update(dt)
for player in pairs(players) do -- We can also do game.World.Each("Identity") or `game.Players.All()`, but that's slower since it has to refind all of those values every time it's called. I mean, it's negligibly slower in most cases, but Update(dt) runs every frame, so it's in your best interest to keep things quick!
local character = game.Players.CharacterOf(player) -- Finds the player character from our list
if character ~= nil and character:IsAlive() and not given[player] then
table.insert(character.Slots, tool) -- The tool is now in their backpack!
character.Active = tool -- To equip the tool, this needs to be set
given[player] = true -- Keeps track that we equipped the tool without needing to constantly check the character slots
end
end
end
I explain how the script works in the comments. All you need to do now is run the game, and you’ll see that the tool has been equipped to your avatar!
edit: game.Session is being deprecated and people are still linking to it, so I updated the code. Some dumb typos and incorrect endpoint names were in the comments so I fixed that too