The code is in a local script
The point of the script is when a player of the name "LoganboyInCO" (which is me) joins the game I custom hat I made in ReplicatedStorage
gets cloned and it's parent is changed to my player (player in workspace) but that doesn't seem to work?
Anything wrong?
game.Players.PlayerAdded:Connect(function(player) if player.Name == "LoganboyInCO" then game.ReplicatedStorage.gokuhair:Clone().Parent = game.Players.LocalPlayer.Character end end) -- written by loganboyinco
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() -- this was necessary because I'm not sure why, when you use :AddAccessory, the instance doesn't get cloned, instead, it gets parented. 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 ¯_(?)_/¯
Merely cloning this hat will not produce the result which you are looking for (you're also cloning it to the Character, and not their head) - you need to attach it, which unfortunately :AddAccessory() cannot be run from the client.
You need to either run AddAccessory() from the server - or use TheGamer101's intuitive client-side solution, which can be found below:
https://devforum.roblox.com/t/humanoid-addaccessory-does-not-work-with-fe-from-a-localscript/33657/4
This should work
game.Players.PlayerAdded:Connect(function(player) if player.Name == "LoganboyInCO" then local gokuhair = game.ReplicatedStorage.gocuhair:Clone() gokuhair.Parent = player.Character local weld = Instance.new("Weld") weld.Parent = player.Character weld.Attachment0 = player.Character.Head weld.Attachment1 = gokuhair end end) -- written by loganboyinco