So i was working on a hatgiver server script. When the player hits the script parent it gives the player An accesory(AngelWings)
Wait(3) Script.Parent.Touched:Connect(function(hit) If hit. Parent:FindFirstChild("humanoid") then workspace.(myplayername).Humanoid:AddAccessory(game.ServerStorage.AngelWings) end end)
It works well but after i reset my character or if i die it doesnt work heres the output
AngelWings is not a valid member of ServerStorage
This is working before reseting, but not after, cause the :AddAccessory()
function changes he parent of the accessory, so logiclly, the accessory that was stored in server storage is no longer there because we changed its parent, and accessories that are not parented to the player after running the game won't stay there after dying, now what you gotta do is use the :Clone()
function, now this is useful it will make a copy of the instance put in its argument, and like that you're original will stay there and there's no problem with loosing the copy.
Also you're script had a ton of problems such as the (myplayername) thing, how will that work? since each player has a different name how will you do that, this is a situation you're always gonna meet, so pay attention, hit is refering to the player's body parts, thenn doing hit.Parent:FindFirstChild
is refering to the player that touched's humanoid.
So this is probarly your script
wait(3) local accessory = game:GetService("ReplicatedStorage").AngelWings:Clone() -- this is how you gotta use :Clone script.Parent.Touched:Connect(function(hit) if hit. Parent:FindFirstChild("humanoid") then workspace.(myplayername).Humanoid:AddAccessory(accessory) end end)
It doesn't work after you reset because you already used it and it's gone after it's on your character.
wait(3) script.Parent.Touched:Connect(function(hit) if(hit.Parent:FindFirstChild("Humanoid")) then hit.Parent.Humanoid:AddAccessory(game.ServerStorage.AngelWings:Clone()) end end)
This script clones the wings and uses that clone to put on your character so you never "run out" of them.