#invisibility item not working (code included)
1 messages · Page 1 of 1 (latest)
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
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
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
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
I want to make the handle transparency 0 like the body parts
Tool.parent is the person holding it
Can u send ss in explorer
ok
And circle the relevant parts
** You are now Level 7! **
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
If im understanding this correctly, you want to get every child that is an accessory?
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
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
wait
Reason for it being a new function is so its reusable
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
U put the second function outside of the scope of any other function
wait
it'll just be made for general use and is useful here
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
o
;compile
function testFunction()
local testVariable = "Hello"
printFunction(testVariable)
end
function printFunction(variable)
print(variable)
end
testFunction()
Hello
ok
;compile
function testFunction()
local testVariable = "Hello"
printFunction("Test")
end
function printFunction(variable)
print(variable)
end
testFunction()
Test
This is also possible
will that work for a tool activated function as well?
Depends what u are doing
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
The function we need to handle the filtering would be setup like this:
function FilterArrayByClass(filterArray, class)
-- filter code here
end
We are going step by step rn
ok
First step is filtering the array
also im assuming u removed the string inside the brackets inside getchildren right
Its not
im making the function that gets the body parts and hats
Can you tell me what you are doing rn
im making an Equipped Connect Function that gets all the body parts and accessories in the character holding the tool
Are you remaking your entire code? Cause if so stop right now
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()
should i put that in the equip function
wait not equip
i meant activated
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
but if its not in the activate function the tool.parent would be the player not the character
you're replacing this with the code i sent
Send SS of what u have right now, and preferably include the line numbers
Alright cool
Now we can go about this in 2 different ways:
- We make a function and filter them seperately to loop through (my recommendation)
- loop through the array and use if statements to check what we need to do with it
What do you want to do
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
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
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
ok
Inside the function your goal is the following:
- Create a new empty array
- Loop through the array with a key, value for loop
- in the loop check if the class matches with the given class variable.
- if it matches you insert it into the empty array you created
- After the for loop you return the new array
Just try to do this and show me the code once you're done
there is some terminology i dont know
also i gotta do something rq
Okay
there is already a working official roblox item called the invisibility cape, if you want to take from toolbox.
those are probably copies of the item and probably work just as well
Can you send the link from the roblox one? Copies of the item could have malicious code in them so its a bit riskier
ok im back
wb
what does that mean
welcome back
o thanks
is this what will find the body parts and stuf
Thats the loop to iterate through the array
no
o
its step 2
it loops through the array of the function
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
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
ooooh
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
The script is in the tool right?
yes
localscript then
ok
since its part of the player/character
oooh yea
so for the part that says "--code" should i just do Getchildren or Waitforchild or something like that?
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)
but the charchildren is in the activated connect, which comes after filterarraybyclass function
Do you know how functions work?
uhhh
kinda
there like
bits of code that u can call on later
im kinda new to scripting
Some things have “invisible returns” because Roblox already privides it. For example, if the player touched a part, then roblox would have the part that touched it be a return value of the event. So, in brief terms: Part gets touched, part is the first parameter of the touched event Other events like PlayerAdded and PlayerRemoved have a pa...
See if that helps you understand them
im gonna try something
uhhhh
im kinda confused on what i should put after the for _, v in filterarray part
aka line 5
Do you understand how for loops work?
i think so
for the number in range it repeats that thing that many times
but there isnt rly a number
This is a different for loop
so if theres no number it'll keep doing that until there is no stuff to return
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)
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
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
ooooh
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
but since its a local script i wont be able to see the print
wait nvm
the output window shows prints from anywhere
i put the print statement in the for loop but nothing came out
Did u do this
Did u insert that code
Read the msg
Yep
SO THE ACTIVATE FUNCTION CALLS THAT ONE
So you need to call it
Yuh
the charchildren thing has squiggly lines under it
** You are now Level 8! **
its causing a syntax error
did uuu capitalize it correctly
do we need to define charchildren somewhere beforehand
alr
ok i corrected my mistake im gonna test it agian
WHOA
it got all the stuff in my avatar
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
dang
And the value is the instance
i didnt know u could like
carry stuff to functions that are farther towards the beginning of a script
Yea u can
for some reason i always assumed that like
function dont care about the scope when it comes to the parameters. if u pass a variable, it uses that variable
Cool
so now we need to make it filter out all the other stuff and only get body parts and accessories
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
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
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
Well it worked even with stuff it shouldnt work with
And also we are trying to prepare the code so it can easily be used in the future aswell
oh yea