Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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
0
Clone() needs to reference an existing object, is the original object somewhere else too? ABK2017 406 — 5y
0
^ Clone works perfectly fine in this instance. The object exists within ReplicatedStorage and is being replicated to the character - but assumably not attached. SummerEquinox 643 — 5y
0
Also - running PlayerAdded from the client will not catch when you join, only when other players join. @OP SummerEquinox 643 — 5y
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. SummerEquinox 643 — 5y
View all comments (3 more)
0
The script is in workspace. LoganboyInCO 150 — 5y
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. Astralyst 389 — 5y
0
also, why are you using a localscript for this? It should work fine with just a serverscript. Astralyst 389 — 5y

3 answers

Log in to vote
1
Answered by
Astralyst 389 Moderation Voter
5 years ago
Edited 5 years ago

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

0
The script doesn't work. LoganboyInCO 150 — 5y
0
oh my god the indentation User#19524 175 — 5y
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. SummerEquinox 643 — 5y
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. Astralyst 389 — 5y
View all comments (3 more)
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) Astralyst 389 — 5y
0
edited my post by the way Astralyst 389 — 5y
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) LoganboyInCO 150 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
Whats that supposed to mean? LoganboyInCO 150 — 5y
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
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. SummerEquinox 643 — 5y
0
I'll edit it FirezoneGamez 155 — 5y
0
should work now FirezoneGamez 155 — 5y
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. SummerEquinox 643 — 5y
View all comments (3 more)
0
This script doesn't work either. (I have the script as a server script in workspace) LoganboyInCO 150 — 5y
0
check my post, i edited it. Astralyst 389 — 5y
0
should be in server script service to work FirezoneGamez 155 — 5y

Answer this question