Importing Catalog items through script

Hello, so I have a script which is suppose to make the id in the textbox import into roblox, though I am very new to accessory part of scripting, here is my script

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		script.Parent.FocusLost:connect(function(enterPressed)
			if enterPressed then
				local Load = game:GetService("InsertService"):LoadAsset(script.Parent.Text)
				Load.Parent = character
				for i, v in pairs(Load:GetChildren()) do
					v.Parent = character
				end
			end
		end)
	end)
end)

I think you have to convert the Text to a number since Text is automatically a string. You’ll have to do some filteing to ensure what was given is a number, but for now, you could do

local Load = game:GetService("InsertService"):LoadAsset(tonumber(script.Parent.Text))

Didn’t seem to work just tested it.

Okay trouble shooting time

What happens if you print the children of Load, any errors? Are you remembering to press enter?

Nothing seems to print in output when putting a print for printing the children of load in the code.

There’s the issue then, okay so firstly, what are you trying to load in?

Dominus Empyreus - Roblox Just this random hat

It is in a CharacterAdded event so it may be waiting for a new character to be added. What if you take it out of the CharacterAdded event

It is not possible to get character without the playeradded.

Wait yea now taht I see it carefully, why is in a PlayerAdded and characterAdded? Couldn’t you just make it a separate event and just parent it to the local player’s character? This is in a Localscript correct?

You can just do player.Character to get the character

It’s in a server script. localplayer.character wouldnt work.

Server scripts can’t see text inputted by the client. You will have to change it to a local script. To get the player you can do game.Players.LocalPlayer and game.Players.LocalPlayer.Character to get their character

1 Like

Convert it to a localscript and make it so when Focus is lost by an enter press, parent the Asset to the Localplayer

1 Like

Yea, but insertservice doesn’t work it in a localscript

You will have to use remote events to send the text to a server script

Can’t you use a RemoteEvent then to pass in the given id and insert it using a Server sided Remote?

I’m gonna better the code real quick.

local PLAYER_SERVICE = game:GetService("Players")

local PLAYER = PLAYER_SERVICE.LocalPlayer or PLAYER_SERVICE:FindFirstChild("NameHere") or PLAYER_SERVICE:WaitForChild("NameHere")
-- We wait for PLAYER variable to be available, then we move on from there.
local CHARACTER = Player.Character or Player.CharacterAdded:Wait()


script.Parent.FocusLost:connect(function(ENTER_PRESSED)
      if ENTER_PRESSED then
            -- I copied and pasted the code to here.
            local Load = game:GetService("InsertService"):LoadAsset(script.Parent.Text)
				Load.Parent = character
				for i, v in pairs(Load:GetChildren()) do
					v.Parent = character
				end
      end
end)

And also, you should’ve just done this.

I will just use remote events, thanks for the advice. I marked your answer as solution.

1 Like