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

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

Asked by
eggxie 2
5 years 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 Ziffixture 6913 — 5y
0
You’re using Deprecated methods too, :clone() :connect, they should all have Uppercase beginning letters. Ziffixture 6913 — 5y
0
great tips thank you so much!!! i fixed it and it's perfect! eggxie 2 — 5y

2 answers

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years 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 — 5y
Ad
Log in to vote
-1
Answered by 5 years 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 — 5y

Answer this question