#invisibility item not working (code included)

1 messages · Page 1 of 1 (latest)

icy venture
#

idk why i feel like i did everything irght

#

when i press it, it says "attempted to index nil with transparency" (refering to hats.Handle.Transparency)

#

and before i added handle after hats it also didnt work

swift wren
#

What is that hats thing

#

why are you doing tool.Parent:GetChildren("Accessory")

#

GetChildren is used without arguments to get all children of a parent, and puts it in an array

icy venture
#

O

#

So wut should I do instead

swift wren
#

If u want one child, use FindFirstChild or WaitForChild

#

WaitForChild yields the function until it finds child

#

FindFirstChild just gets it

#

and if it fails itll just continue

#

If u use WaitForChild i'd recommend having a timeout aswell

#

Which u put after specifying the object

icy venture
#

So I should get all the parts individually with WaitForChuld?

#

Child*

swift wren
#

What are you planning to do with hats?

#

Can u show in the explorer what tool.Parent is and what u are trying to get

icy venture
#

I want to make the handle transparency 0 like the body parts

#

Tool.parent is the person holding it

swift wren
#

Can u send ss in explorer

icy venture
#

ok

swift wren
#

And circle the relevant parts

icy venture
#

o lemme do the circling rq i was about to send it already

#

ok

serene groveBOT
#

studio** You are now Level 7! **studio

icy venture
#

wait fuck

#

its not the edited version hold on

#

ok here it is

#

ignore those localscripts theyre for something else i did in game

#

just ignore everything that isnt circled

swift wren
#

If im understanding this correctly, you want to get every child that is an accessory?

icy venture
#

yes

#

and also the body partsa

#

parts*

#

and the tool.parent is the character holding it, though that only works if its in the activated function

swift wren
#

So you need to get children and then filter the children to only include the class that u need

#

U cant do this in the arguments of getchildren, because getchildren takes no arguments

#

What i'd recommend is making a new function to handle the filtering

#

Parameters for the function would be the table, and what class to filter it by

icy venture
#

wait

swift wren
#

Reason for it being a new function is so its reusable

icy venture
#

wait

#

but theres also the tool actrivated function

#

so idk how two functions in 1 script would act together

#

cuz wouldnt it just not let the second function works

#

work*

#

wait nvm i misunderstand it

#

i think i have an idea

swift wren
#

U put the second function outside of the scope of any other function

icy venture
#

wait

swift wren
#

it'll just be made for general use and is useful here

icy venture
#

but if its a variable/table from 1 function i dont think it can be used in other functions

#

cuz

#

when u define something in a function u hbave to make it local

swift wren
#

Yes it can

#

Lemme show an example

icy venture
#

o

swift wren
#

;compile

function testFunction()
  local testVariable = "Hello"
  printFunction(testVariable)
end
function printFunction(variable)
  print(variable)
end
testFunction()
dreamy stoneBOT
#
Program Output
Hello

swift wren
#

See

#

The variable of the new function will be whatever u gave it

icy venture
#

ok

swift wren
#

;compile

function testFunction()
  local testVariable = "Hello"
  printFunction("Test")
end
function printFunction(variable)
  print(variable)
end
testFunction()
dreamy stoneBOT
#
Program Output
Test

swift wren
#

This is also possible

icy venture
#

will that work for a tool activated function as well?

swift wren
#

Depends what u are doing

icy venture
#

so after i make the function that gets all the body parts and accessories im gonna use that table to make them transparent for a set amount of time

swift wren
#

The function we need to handle the filtering would be setup like this:

function FilterArrayByClass(filterArray, class)
  -- filter code here
end
icy venture
#

ok

swift wren
#

First step is filtering the array

#

also im assuming u removed the string inside the brackets inside getchildren right

icy venture
#

its not a string its a variable

#

wait hold on

swift wren
#

Its not

icy venture
#

im making the function that gets the body parts and hats

swift wren
#

Can you tell me what you are doing rn

icy venture
#

im making an Equipped Connect Function that gets all the body parts and accessories in the character holding the tool

swift wren
#

Are you remaking your entire code? Cause if so stop right now

icy venture
#

o

#

ok ill stop

#

ok i just brought back the old code that i screenshotted

swift wren
#

Okay good

#

Ill walk you through it a bit more descriptive

#

First to get the children i'd recommend just making 1 variable like the following:

local charChildren = tool.Parent:GetChildren()
icy venture
#

wait not equip

#

i meant activated

swift wren
#

that would replace the hats and bodyparts

#

u are grabbing them all into one array

#

lmk when you've done it and show me the code

icy venture
#

but if its not in the activate function the tool.parent would be the player not the character

swift wren
#

you're replacing this with the code i sent

icy venture
#

ok

swift wren
#

Send SS of what u have right now, and preferably include the line numbers

icy venture
swift wren
#

Alright cool

#

Now we can go about this in 2 different ways:

  1. We make a function and filter them seperately to loop through (my recommendation)
  2. loop through the array and use if statements to check what we need to do with it
#

What do you want to do

icy venture
#

hmm

#

i say the first one

swift wren
#

Alrighty

#

Lets start with the function to filter the array then

#

If you want I can make it for you and describe in depth on what it does

icy venture
#

u dont gotta make it for me i just needed some help defining the body parts and hats to make them invisible

#

i just want it to make the user invisible after activating it

swift wren
#

yea but obtaining all the different parts isnt that simple

#

But alr ill help you step by step

#

So first just make a new function like the following.

function FilterArrayByClass(filterArray, class)

end
icy venture
#

ok

swift wren
#

Inside the function your goal is the following:

  1. Create a new empty array
  2. Loop through the array with a key, value for loop
  3. in the loop check if the class matches with the given class variable.
  4. if it matches you insert it into the empty array you created
  5. After the for loop you return the new array
#

Just try to do this and show me the code once you're done

icy venture
#

ok

#

wait

#

on step 2

#

is the key itself the value for the loop

swift wren
#

u dont really need the key

#

u only need the value

icy venture
#

there is some terminology i dont know

swift wren
#

u can just discard the key

#
for _, v in filterArray do

end
icy venture
#

o

#

ok lemme make the empty array first

swift wren
#

u can name "v" whatever u want btw

#

since its just a new variable

icy venture
#

also i gotta do something rq

swift wren
#

Okay

junior timber
#

there is already a working official roblox item called the invisibility cape, if you want to take from toolbox.

swift wren
#

Where

#

Im searching for it i just see loads from other people

junior timber
#

those are probably copies of the item and probably work just as well

swift wren
#

Can you send the link from the roblox one? Copies of the item could have malicious code in them so its a bit riskier

icy venture
#

ok im back

swift wren
#

wb

icy venture
#

what does that mean

swift wren
#

welcome back

icy venture
#

o thanks

icy venture
swift wren
#

Thats the loop to iterate through the array

icy venture
#

oh

#

the empty one i make in step 1?

swift wren
#

no

icy venture
#

o

swift wren
#

its step 2

icy venture
#

ik

#

wait

#

about step 2

#

what is there to loop through?

#

if the array is empty

swift wren
#

it loops through the array of the function

icy venture
#

hold on we might be like

#

both confused

#

lemem ss what i have so far

#

i did step 1 and started step 2 then i had to go do something my parents neede

#

and now im back

swift wren
#
function FilterArrayByClass(filterArray, class)
  local returnArray = {}
  for _, v in filterArray do
    -- code
  end
end

This is what we should have so far based on what you've done and what ive given

icy venture
#

ooooh

swift wren
#

the purpose of the empty array is so we can insert the parts the match into a separate array without risking breaking the current loop and array

icy venture
#

ok

#

also

#

does it matter if its in a normal script or a local script

swift wren
#

The script is in the tool right?

icy venture
#

yes

swift wren
#

localscript then

icy venture
#

ok

swift wren
#

since its part of the player/character

icy venture
#

oooh yea

#

so for the part that says "--code" should i just do Getchildren or Waitforchild or something like that?

swift wren
#

Neither

#

You pass an array to the function

#

the array you pass is the array of all the children after doing :GetChildren (which was put in the charChildren variable)

icy venture
#

but the charchildren is in the activated connect, which comes after filterarraybyclass function

swift wren
#

Do you know how functions work?

icy venture
#

uhhh

#

kinda

#

there like

#

bits of code that u can call on later

#

im kinda new to scripting

swift wren
#
#

See if that helps you understand them

icy venture
#

im gonna try something

#

uhhhh

#

im kinda confused on what i should put after the for _, v in filterarray part

#

aka line 5

swift wren
#

Do you understand how for loops work?

icy venture
#

i think so

swift wren
#

Explain to me

#

Atleast explain the specific for loop we are using

icy venture
#

for the number in range it repeats that thing that many times

#

but there isnt rly a number

swift wren
#

This is a different for loop

icy venture
#

so if theres no number it'll keep doing that until there is no stuff to return

swift wren
#

What we are using is a key, value for loop. In this for loop u iterate through the table (the variable after "in"), and go through each item inside it. The key returns the key to access the value (in this case it would be the index 1, 2, 3 etc. But in dictionaries it would be the name). The value is the value of the item that you are at. I will show this in the following example:

#

;compile

local newTable = {
  name = "TestTable",
  size = 10
}
local newArray = {"TestArray", 10}

function IterateArray(filterArray)
  for key, value in pairs(filterArray) do
    print("Key: " .. tostring(key))
    print("Value: " .. tostring(value))
    print("Type of Value: " .. type(value))
  end
end
IterateArray(newTable)
print("----")
IterateArray(newArray)
dreamy stoneBOT
#
Program Output
Key: name
Value: TestTable
Type of Value: string
Key: size
Value: 10
Type of Value: number
----
Key: 1
Value: TestArray
Type of Value: string
Key: 2
Value: 10
Type of Value: number

swift wren
#

damnit

#

gimme a moment this is lua so its diff

#

There we go

#

Thats how for loops work.

#

in luau u dont need pairs to make it work, but in lua you do, and since compiler compiles in lua i wrote that

icy venture
#

ooooh

swift wren
#

If u want before proceeding with the actual script, you can just print(v) in the for loop and see what it returns ingame. You will need to call it, and you can do so like this in the .Activated function:

FilterArrayByClass(charChildren)

This will need to be changed once we proceed but for now its good to check

icy venture
#

but since its a local script i wont be able to see the print

swift wren
#

Why not?

#

U check it via output

icy venture
#

wait nvm

swift wren
#

the output window shows prints from anywhere

icy venture
#

i put the print statement in the for loop but nothing came out

swift wren
#

Did u insert that code

icy venture
#

oh

#

do i also put that in the for loop or does it go somewhere else

swift wren
#

Read the msg

icy venture
#

OOO

#

OOOH CUZ THE PRINT THING IS IN THE FIRST FUNCTION BUT ITS NOT FCALLED YET

swift wren
#

Yep

icy venture
#

SO THE ACTIVATE FUNCTION CALLS THAT ONE

swift wren
#

So you need to call it

icy venture
#

OOOOOOOH

#

I UNDERSTAND IT NOW

swift wren
#

Yuh

icy venture
#

the charchildren thing has squiggly lines under it

serene groveBOT
#

studio** You are now Level 8! **studio

icy venture
#

its causing a syntax error

swift wren
#

did uuu capitalize it correctly

icy venture
#

do we need to define charchildren somewhere beforehand

swift wren
#

we defined it already

#

in the .Activated function

icy venture
#

i mightve missed something

swift wren
#

Why'd u remove it

#

we had this

#

whyd u remove that line

#

in .Activated

icy venture
#

oooooh

#

idk why

#

i got confused

#

ill ad it back

swift wren
#

alr

icy venture
#

ok i corrected my mistake im gonna test it agian

#

WHOA

#

it got all the stuff in my avatar

swift wren
#

yep

#

Thats cause we got all children of the avatar in the .Activated function, passed that over to the FilterArrayByClass function, and iterated through it there with a for loop

#

Printing the value of each

icy venture
#

dang

swift wren
#

And the value is the instance

icy venture
#

i didnt know u could like

#

carry stuff to functions that are farther towards the beginning of a script

swift wren
#

Yea u can

icy venture
#

for some reason i always assumed that like

swift wren
#

function dont care about the scope when it comes to the parameters. if u pass a variable, it uses that variable

icy venture
#

hmmm

#

i understand it now i think

swift wren
#

Cool

icy venture
#

so now we need to make it filter out all the other stuff and only get body parts and accessories

swift wren
#

So now the next step is checking if it matches the className. I'd recommend using the :IsA function for that

#

lemme get u docs 1 sec

#

What we want to do is:
If the class matches, we want to insert it into the empty array we created.
At the end of the loop we return that array

icy venture
#

ok

#

also we gotta get the handles from the accessories

#

since accessories themselves dont have a transparency property

#

ill just work on getting body parts for now

#

ok i got something figured out

#

i basically added this:

#

if v IsA:("Part") then

#

then it prints v again

#

so anything it detects as a Part gets printed an additional time

#

and it makes the bodyparts invisible

#

so one part of it is working

#

now i just need to get the accessories

#

i did some of it myself :DDDD

#

yipee

swift wren
#

You shouldnt be checking on part

#

Btw in this filter script we arent going to be handling anything for the transparency

#

Only filtering the array and returning

#

Btw the class of the limbs are "MeshPart" and the class of the accessory are "Accessory"

#

Which is what we would be passing in the function when activating it

#

so u dont even need that for making the code in the FilterArray function

#

@icy venture

icy venture
#

but i tested it and it worked

#

lemme record

swift wren
#

Well it worked even with stuff it shouldnt work with

icy venture
swift wren
#

And also we are trying to prepare the code so it can easily be used in the future aswell

icy venture
#

oh yea

swift wren
#

Thats just thinking ahead

#

how does your code look currently

icy venture
#

its not that big

swift wren
#

alr so changes:
Change the argument inside IsA to the class variable. Since we're passing that for that to check with.

#

Next you dont want to change the transparency, since we want to be able to use this function regardless of what our goal with it is