Attachment Thingy

Lately i’ve tried to make a gui that when clicked, makes a mesh/part transparency set to 0. but everytime i click it i get an error in the output saying " AK48 is not a valid member of Workspace “Workspace” " how do i fix this?

Gui Script:

script.Parent.MouseButton1Click:Connect(function()
game.Workspace.AK48.Scope.Transparency = 0
end)

any help would be appreciated! :grinning:

2 Likes

Well, it looks like that AK48 is not a valid children of Workspace.

2 Likes

but im trying to find out how to make it “the valid child” of the workspace. cuz y’k im a bad dev n stuff.

2 Likes

When it says that something is not a valid member of X, it means that the instance you’re looking for doesn’t exist.

It seems like you’re trying to set the transparency of the scope while holding the gun. Here is the script.

Server:

script.Parent.MouseButton1Click:Connect(function()
local Player = script:FindFirstAncestorWhichIsA("Player")
if Player then
 local AK48 = Player.Character:FindFirstChild("AK48")
 if AK48 then
  workspace.AK48.Scope.Transparency = 0
 end
end
end)

If you are curious by how they work, FindFirstAncestor is the opposite of FindFirstChild, only used for finding a parent, while FindFirstChild finds an instance inside of a parent.

When they can’t find an instance they’re looking for, they’ll return nil, which can be used for if then statement for checking object existence.

2 Likes

thank you! it actually worked.