I tried that, it’s the same thing used for the face, but it’s really confusing for me .
Well, the same way you did it for face.
I’ve tried, doesn’t seem to work.
I’m on mobile, sorry if I mess a few things up.
local Input = --Reference the input box.
local hatID = Input.Text
for i,v in pairs(game:GetService("InsertService"):LoadAsset(hatID):GetChildren()) do
v.Parent = player.Backpack --Reference the player beforehand.
end
The reason I used :GetChildren()
is because the asset gets loaded in as a model, so we would need to get the accessory which is a descendant of the model.
It should be noted you should use MarketPlaceService to check the asset type of something you’re going to be potentially inserting because if a user inputs for example a model they uploaded with a script they could potentially run code on your game.
Perhaps she could use if v:IsA("Accessory")
? Or I may be wrong.
I attempted to use this and it came with this error: I don’t think the text is being picked up after apply has been clicked.
Current script:
script.Parent.Parent.hatApply.MouseButton1Click:Connect(function(player)
local Input = script.Parent
local hatID = Input.Text
for i,v in pairs(game:GetService("InsertService"):LoadAsset(tonumber(hatID)):GetChildren()) do
v.Parent = player.Backpack
end
end)
MY BAD!! I have no idea why I said to add it to the Backpack, it should be the Character.
So something like:
script.Parent.Parent.hatApply.MouseButton1Click:Connect(function(player)
local Input = script.Parent
local hatID = Input.Text
for i,v in pairs(game:GetService("InsertService"):LoadAsset(tonumber(hatID)):GetChildren()) do
if v:IsA("Accessory") then
v.Parent = player.Character
end
end
On mobile again sorry if I messed up stuff.
I have corrected that in the script now, but argument 1 is still missing or nil.
I noticed it’s being run from a LocalScript? You should use a RemoteEvent so that the hat is visible to all players and not just the client executing the script.
It’s being ran by a script.
Oh, I don’t think MouseButton1Click in PlayerGuis can be run by ServerScripts. I may be wrong, but my current donor/admin panel utilises RemoteEvents; so using LocalScripts only and ServerScripts to carry out the function.
Okay, I’ll try edit it a bit. (30charrss)
I’m lost within seconds lol, is there any way to fit it into this script that handles all the functions?
-- Services --
local InsertService = game:GetService("InsertService")
local RepStorage = game:GetService("ReplicatedStorage")
-- Variables --
local ApplyFace = RepStorage:WaitForChild("ApplyFace")
local RemoveHead = RepStorage:WaitForChild("RemoveHead")
local AddHead = RepStorage:WaitForChild("AddHead")
local ApplyHat = RepStorage:WaitForChild("ApplyHat")
-- Functions --
function ApplyFace_Event(player, id)
local asset = InsertService:LoadAsset(tonumber(id))
local faceid = asset:WaitForChild("face").Texture
if player.Character then
player.Character.Head.face.Texture = faceid
return "Applied"
end
asset:Destroy()
return "Could not apply face"
end
function RemoveHead_Event(player, id)
if player.Character then
player.Character.Head.Transparency = 1
player.Character.Head.face.Transparency = 1
return "Applied"
end
return "Could not remove head"
end
function AddHead_Event(player, id)
if player.Character then
player.Character.Head.Transparency = 0
player.Character.Head.face.Transparency = 0
return "Applied"
end
return "Could not add head"
end
-- Callbacks --
ApplyFace.OnServerInvoke = ApplyFace_Event
RemoveHead.OnServerInvoke = RemoveHead_Event
AddHead.OnServerInvoke = AddHead_Event
Ok, let’s do it like this.
First things first, let’s create a RemoteEvent under our TextButton and name it “RequestAsset”.
Now let’s create a LocalScript that will fire this RemoteEvent whenever the TextButton is clicked (again, under the TextButton).
Ever since workspace.FilteringEnabled
was enforced, any text the client enters into a TextBox was NOT replicated to the server. We want to send the text AND the player in question to the server so that the server knows what assetId to load and what player to load it on.
Something like this;
local RemoteEvent = script.Parent:FindFirstChildWhichIsA("RemoteEvent")
local AssetId = script.Parent.Parent:FindFirstChildWhichIsA("TextBox")
script.Parent.MouseButton1Click:Connect(function()
RemoteEvent:FireServer(AssetId.Text)
end)
I want you to note that I’m assuming you have the TextBox to enter the assetId into and the TextButton we want to press to get the hat is under the same ancestor.
Now let’s create our Script under the same TextButton.
First we’ll want to get the RemoteEvent the player fires;
local InsertService = game:GetService("InsertService") --We'll need this.
local RemoteEvent = script.Parent:FindFirstChildWhichIsA("RemoteEvent")
Alright, now we’ll start listening for any events;
RemoteEvent.OnServerEvent:Connect(function(player, assetId)
local Model = InsertService:LoadAsset(assetId) --We loaded in the asset
if not player.Character then
player.CharacterAdded:Wait() --Just in case the player does not have a character yet
end
for h, g in pairs(Model:GetDescendants()) do
if g:IsA("Accessory") then
g.Parent = player.Character
end
end
Model:Destroy() --Remember to destroy the Model afterwards!
end)
If you did everything correctly, it should look like this: Baseplate.rbxl (23.7 KB)
Good luck. Also an important thing to note (which I initially struggled with) is the parameters of the FireServer() and OnServerEvent functions. The first parameter of the OnServerEvent will be the player executing the script by default, while the second parameter will be the first of the FireServer(). So when assigning the hat, the ServerScript would look something like:
local Remote = game:GetService("ReplicatedStorage").HatRemote --Add the RemoteEvent "HatRemote" in first.
Remote.OnServerEvent:Connect(function(player,ID)
local accessory = game:GetService("InsertService"):LoadAsset(ID):GetChildren()
for i,v in pairs(accessory) do
accessory.Parent = player.Character
end
end)
And the LocalScript in the Gui will be something like:
local Remote = game:GetService("ReplicatedStorage").HatRemote
script.Parent.MouseButton1Click:Connect(function()
local ID = tonumber(script.Parent.Text) --Reference to the text inputted.
Remote:FireServer(ID)
end)
One more thing to note, make sure you add sanity checks in case an exploiter spams the RemoteEvent to lag the server out or uses it for themselves.
I’ve used your script to help me do this, and it worked! Thanks everyone for your help and I hope that I didn’t waste anyones time today!