Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script is unable to clone a custom hat into a player with a certain name?

Tree

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

7 comments

0

Clone() needs to reference an existing object, is the original object somewhere else too?

0

^ Clone works perfectly fine in this instance. The object exists within ReplicatedStorage and is being replicated to the character - but assumably not attached.

0

Also - running PlayerAdded from the client will not catch when you join, only when other players join. @OP

0

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.

0

The script is in workspace.

0

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.

0

also, why are you using a localscript for this? It should work fine with just a serverscript.

3 answers

✓ 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() -- 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 ¯_(?)_/¯

7 comments

0

The script doesn't work.

0

oh my god the indentation

0

Yeah the indention is a yikes lol - but Logan, both of our answers have answered your question. You are probably doing something wrong setup-wise. Remember that this isn't a request site - you have to be willing to try and do some of the work on your own.

0

the issue with my last script is that I mispelled the variable & forgot to add a ) to one end, it could've been fixed easily if you actually looked at the red underlines.

0

anyways, I fixed it and changed it up a lil, now it should work. (yes, i bothered to get on studio and test it because I thought I was wrong)

0

edited my post by the way

0

I already know this isnt a request site, so dont remind me. The only thing I don't know is the set up. (current set up is a server script in workspace)

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

1 comment

0

Whats that supposed to mean?

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

7 comments

0

This will work - but will not produce his desired result. The issue is that he is not attaching the accessory to the character in any way.

0

I'll edit it

0

should work now

0

:AddAccessory() is a more idiomatic way to add accessories to the character - it unfortunately doesn't work on the client's end - and would be better to run on the server anyway.

0

This script doesn't work either. (I have the script as a server script in workspace)

0

check my post, i edited it.

0

should be in server script service to work

This discussion is preserved as it was. New answers, comments, and votes are closed.