Using InsertService to insert Items

Hello developers! Today i’m going to be teaching you a simple script using InsertService, then we will use the item imported to give a certain player or everyone a hat.

All right, so first up we need to Insert our item using the “InsertService”. Steps below:

Locate the "Run A Command" bar at the bottom of roblox studio. Image in here if needed.

Insert the following code in Run to use InsertService
local id = 000000 --replace with your item ID
game:GetService("InsertService"):LoadAsset(id).Parent = workspace

Now your item will be inserted, so let’s use it for something!

All Players

In this section we will make a ServerScriptService script that gives everyone the item you inserted

Steps:
1: Ungroup your item
2: Drag the accessory into "ServerStorage"
3: Rename the accessory to “Hat” should look like the image below:
image
4: Paste this code in a script in ServerScriptService (Name the script anything)

local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")

players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function(character)
		local hat = serverStorage:WaitForChild("Hat") -- Hat were cloning into the player
			local clone = hat:Clone()
			clone.Parent = character
 end)
end)
Certain Players

In this section we will make a ServerScriptService script that gives certain players the item you inserted.

Steps:
1: Ungroup your item
2: Drag the accessory into "ServerStorage"
3: Rename the accessory to “Hat” should look like the image below:
image
4: Paste this code in a script in ServerScriptService (Name the script anything)

local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")

local users = {
	0000000000, -- User ID's (you can add more but make sure to add a comma until last one.)
    0000000000
}

local isAllowed = function(player, tab)
	for i, v in pairs(tab) do
		if player.UserId == v then return true end
	end
	return false
end

players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function(character)
		local hat = serverStorage:WaitForChild("Hat") -- The hat were cloning into the player
		if isAllowed(player, users) then
			local clone = hat:Clone()
			clone.Parent = character
		end
	end)

end)

Helpful docs for this tutorial:

:link:InsertService Docs
:link:Clone Doc (Scroll to find)
:link:Parenting

Hopefully this helped some people, let me know if you have any issues or need any open source script’s posted. Please feel free to like this post so more people can see it!

2 Likes