I used GetChildren here to get these multiple fireball shots and slowly delete them. But it will always say transparency is nil. What am I doing wrong here? How can I fix it?
local fireballs = Character:GetChildren("FireBall") repeat wait(.1) fireballs.Transparency = fireballs.Transparency + .1 until fireballs.Transparency >= 1
:GetChildren()
returns a table (and takes no arguments, so you saying "FireBall" does nothing). In lua, you cannot apply an action to a table in order to apply that action to everything within it. That is, when you say fireballs.Transparency =
, lua assumes you're trying to change the table rather than the list of children. To change the children, you have to use a for
loop, like so:
local ch = Character:GetChildren() local fireballs = {} -- This creates a new table. We will use it to keep track of the parts we're interested in (fireballs). for i = 1, #ch do -- For each child: if ch[i].Name == "FireBall" then -- If this child (ch[i]) has the right name, add it to our list table.insert(fireballs, ch[i]) -- you can also do: fireballs[#fireballs + 1] = ch[i] end end if #fireballs > 0 then -- The "until" line will error if there aren't any fireballs repeat wait(0.1) -- wait once and then, for each fireball, increase its transparency for i = 1, #fireballs do fireballs[i].Transparency = fireballs[i].Transparency + .1 end until fireballs[1].Transparency >= 1 -- Notice that 'i' doesn't exist here so we need to access one of the fireballs; we look at the first one to see when to stop end --Alternatively, you could use a for loop (but don't keep both): for i = 0.1, 1, 0.1 do wait(0.1) for j = 1, #fireballs do fireballs[j].Transparency = i -- In this case, 'i' is the transparency and 'j' is which fireball we're working with end end
For i,v in pairs instead?