function loadHats()
local hatItem = insertService:LoadAsset(hats:FindFirstChild(hatID).ItemID.Value)
local realHat = hatItem:GetChildren()[1]
realHat.Parent = workspace.Dummy
hatItem:Destroy()
end
To my knowledge, this should load the hat into the dummy model (it does yes) but it’s puts it doesn’t put the accessory where it should be positioned (it’s a shaggy) I did a test in a separate place and it seemed to work, but for some reason on my place it just loads the item a mile away. How can I get it to load in the correct spot (as if someone was actually wearing the item)
1 Like
Oh ok, well when I did it in a different server it loaded the hats onto the dummy properly
I tried it, doesn’t work, has this error:
21:57:49.680 - Unable to cast value to Object
The parameter is the accessory ID. I’m not gonna be going and implementing every accessory myself, as the games gonna have 200+ accessories. That’s why I wanted to use LoadAsset to just get the asset through scripting instead of having to add the model in and what not
Are you sure you’re giving it an asset ID as the parameter? Like it’s an integer?
Yeah, the parameter is a value (NumberValue)
To me, from what I’ve read, AddAccessory expects you to add the accessory that’s already stored somewhere within the game, which I ain’t gonna get 200 accessories and store them all myself
Okay I see. What I meant was to load the hat in with InsertService and then use AddAccessory to put it on the character. Hopefully that makes sense.
Oh ok, I think that should work, but still, to what I’ve tested, LoadAsset and parenting it to a character model puts it in the correct spot. For some reason it just doesn’t want to do that in my place
AddAccessory should automatically weld it and stuff.
Oh ok, I think I get it now I’ll give it a shot thanks
Not working (doing the exact same thing as just using LoadAsset)
As you can see from the outline box (I have the dummy model selected) the reason the outline box is so big is because of the hat being added (without the hat the box just outlines the dummy) So the hat is still being added to the dummy, but it still isn’t being positioned correctly
The dummy is just a R15 rig loaded from the animation plugin Roblox has and so all the parts inside the dummy are named properly (Head, etc)
And when I test in my seperate place, it works in Play Solo but not online
I’ve had this problem quite a few times before too. Try this code:
function weldAttachments(attach1, attach2)
local weld = Instance.new("Weld")
weld.Part0 = attach1.Parent
weld.Part1 = attach2.Parent
weld.C0 = attach1.CFrame
weld.C1 = attach2.CFrame
weld.Parent = attach1.Parent
return weld
end
local function buildWeld(weldName, parent, part0, part1, c0, c1)
local weld = Instance.new("Weld")
weld.Name = weldName
weld.Part0 = part0
weld.Part1 = part1
weld.C0 = c0
weld.C1 = c1
weld.Parent = parent
return weld
end
local function findFirstMatchingAttachment(model, name)
for _, child in pairs(model:GetChildren()) do
if child:IsA("Attachment") and child.Name == name then
return child
elseif not child:IsA("Accoutrement") and not child:IsA("Tool") then -- Don't look in hats or tools in the character
local foundAttachment = findFirstMatchingAttachment(child, name)
if foundAttachment then
return foundAttachment
end
end
end
end
function addAccoutrement(character, accoutrement)
accoutrement.Parent = character
local handle = accoutrement:FindFirstChild("Handle")
if handle then
local accoutrementAttachment = handle:FindFirstChildOfClass("Attachment")
if accoutrementAttachment then
local characterAttachment = findFirstMatchingAttachment(character, accoutrementAttachment.Name)
if characterAttachment then
weldAttachments(characterAttachment, accoutrementAttachment)
end
else
local head = character:FindFirstChild("Head")
if head then
local attachmentCFrame = CFrame.new(0, 0.5, 0)
local hatCFrame = accoutrement.AttachmentPoint
buildWeld("HeadWeld", head, head, handle, attachmentCFrame, hatCFrame)
end
end
end
end
That’s from this thread: Humanoid:AddAccessory does not work with FE from a LocalScript - #4 by TheGamer101
Basically, it creates the welds and stuff manually. Just call addAccoutrement() with the character and accessory model. That should work.
1 Like
Inside Local or Server script?
It depends on what you’re doing. It should work in both.
Well I’m trying to get the hat into a dummy on CurrentCamera, so I’ll do local
I can’t get it to work, but I believe I know the problem. In the server script, it parents the accessory to workspace, and when it gets put in the workspace, the localscript creates a clone and sets the clones parent to the dummy model. The problem is that since I set it’s parent to workspace, it will be put back there. I need to figure out how to parent it straight to the dummy model, instead of having to put it somewhere in storage, it needs to be parented immediately to the dummy
Why not just load all the items into ReplicatedStorage once, then have the clients clone them from there?
It seems like each time they want a hat, you have to load it on the server first, then on the client. It would be better if you just loaded all the hats once and were done. It would probably make this much easier to do too.
I cant load them into RepStorage though because then when I clone the hat to the dummy it wont be positioned properly (they’ll just be positioned at wherever they spawn in (usually 0,0,0)) unless I went into workspace and meticulously placed every single hat item to spawn in a somewhat close spot, which is way too much work when you consider I’d have to place each hat + 200 times. Only way I can see this working is the item being parented to the dummy model as soon as they are inserted into the game. They can’t be put in a storage spot or else they’ll just be cloned to that spot and not on the dummy.
Edit: I tried to fire the RemoteEvent back with the parameter being the loaded asset but it just says it a nil value