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

[Solved] Accesory is not a valid member of serverstorage?

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

3 comments

1

Shouldn't you use clone?

1

The error explains itself?

0

I mean it works before i reset character

2 answers

✓ Accepted answer

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) 

3 comments

0

Thanks it worked i know my script was a mess because i was just working on it

0

its go! always practice.

0

ok*

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.

2 comments

0

Thanks for your answer but this doesnt work it doesnt clone the wing

0

That is the method I use to clone things and it works for me but ok then.

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