✓ Accepted answer
I'm not sure why do you need to make this script a LocalScript, when it should work just fine as a ServerScript.
First thing's first, when you clone something into another thing, it doesn't automatically position themselves ontop or anywhere near them.
Let's say, you have Part A and Part B.
Part A is; let's say 1000 studs away from Part B and you want to move it to Part B.
You can't just simply do
workspace["Part A"].Parent = workspace["Part B"]
What'd that do is just simply move the instance "Part A" into Part B, it'll be parented.
The position of Part A won't change in the slightest, it'll remain there.
^ this is the general idea of what I'm talking about; which is also what you're currently attempting to be doing.
This would fix the issue for you -
game.Players.PlayerAdded:connect(function(player)
player.CharacterAppearanceLoaded:connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
if player.Name == "LoganboyInCO" then
humanoid:AddAccessory(game.ReplicatedStorage.gokuhair)
end
humanoid.Died:connect(function()
character:FindFirstChild("gokuhair").Parent = game.ReplicatedStorage
end)
end)
end)
That would need to be in serverscript, but if in the case of no matter what, you must use localscript to do the whole thing, I guess then I couldn't help you because I don't think it's even possible ¯_(?)_/¯
7 comments
Clone() needs to reference an existing object, is the original object somewhere else too?
^ Clone works perfectly fine in this instance. The object exists within ReplicatedStorage and is being replicated to the character - but assumably not attached.
Also - running PlayerAdded from the client will not catch when you join, only when other players join. @OP
If this is a script inside every player, multiple hat instances will be created. There is also the issue that you cannot do this: Clone().Parent, these must be seperate lines afaik.
The script is in workspace.
I've been using :Clone().Parent = for a long time, so it should work fine. ^ the problem is because his script, it directly clones the hat into the character, it's not cloned to the head and even if it is, it won't be attached.
also, why are you using a localscript for this? It should work fine with just a serverscript.