Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

..."instance is not a valid member of"...?

Asked by
eggxie 2
6 months ago

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

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

2 answers

Log in to vote
0
Answered by
RubenKan 3478 Moderation Voter Administrator Community Moderator
6 months ago

You're trying to literally find an instance named img on your serverscript, if you want to use your string variable, you'll have to use [variable], so

local morph = game.ServerStorage.Morphs[img]

This will also fix your localscript error, as that simply refers to the error on the server.

0
thank you so much!! eggxie 2 — 6mo
Ad
Log in to vote
-1
Answered by 6 months ago

make sure all names match including caps local script

script.Parent.MouseButton1Click:connect(function()

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local morph = ReplicatedStorage:WaitForChild("Morph")

    local img = script.Parent   ---i moved the last part Name 

    morph:InvokeServer(img.Name)
    print("decal id: "..img.Name)

    end)

if it does not work tell me and i will fix my answer

0
this didn't work. i dont know what the issue is because the server script prints "img" correctly every time. line 4: print("decal id recieved: "..img) eggxie 2 — 6mo

Answer this question