i'm creating a paper morph GUI with a remote function that will send the name of the button clicked to the server, and it will use that information to clone the correct morph and weld to the player. i'm pretty new at scripting and this is the most advanced thing i've taken on so far, so its probably messy i know.
localscript:
script.Parent.MouseButton1Click:connect(function()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local morph = ReplicatedStorage:WaitForChild("Morph")
local img = script.Parent.Name
morph:InvokeServer(img)
print("decal id: ",img)
end)
server script:
ReplicatedStorage = game:GetService("ReplicatedStorage")
function morphPlayer(player,img)
print("decal id recieved: "..img)
if player.Character:findFirstChild("Humanoid") ~= nil then
--===
local morph = game.ServerStorage.Morphs.img
--===
local chest = game.ServerStorage.Morphs.morphvalue.Chest:clone()
chest.Parent = player.Character
local a = player.Character:GetChildren()
for i=1, #a do
if (a[i].className == "Part") then
a[i].Transparency = 1
local b = player.Character:GetChildren()
for i=1, #b do
if (b[i].className == "Accessory") then
b[i]:remove()
end
local children = chest:GetChildren()
for i=1, #children do
if children[i].className == "Part" then
local W = Instance.new("Weld")
W.Part0 = chest.Middle
W.Part1 = children[i]
local CJ = CFrame.new(chest.Middle.Position)
local C0 = chest.Middle.CFrame:inverse()*CJ
local C1 = children[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = chest.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = player.Character.Torso
Y.Part1 = chest.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local child = chest:GetChildren()
for i = 1, # child do
if child[i].className == "Part" then
child[i].Anchored = false
child[i].CanCollide = false
end
end
end
end
end
end
end
ReplicatedStorage.Morph.OnServerInvoke = morphPlayer
THE ERRORS ARE: img is not a valid member of Folder - localscript line 8
img is not a valid member of Folder - serverscript line 9
when it prints in the output, the name is correct, so I don't know what to do here

3 comments
Try using RemoteEvents, also you’re recursing descendants loops a lot, just use elseif’s to check a different circumstance
You’re using Deprecated methods too, :clone() :connect, they should all have Uppercase beginning letters.
great tips thank you so much!!! i fixed it and it's perfect!