Question on automation for a Wall Jump/ Wall Flick game

I’ve been making my wall jump/wall flick game for a while, but I’ve ran into a issue, it takes way too much time to do the method I have in place for it. my stages are in a folder called stages and are named with a number co-responding to their appropriate stage.
This is how I have been sizing them as it takes to long to use properties

local wj = game.Workspace["Lava Wall Jump"]
print(wj.kp1.Size)
wj.kp1.Size = wj.kp1.Size+Vector3.new(0,0,0.1)
wj.kp2.Size = wj.kp2.Size+Vector3.new(0,0,0.2)
wj.kp3.Size = wj.kp3.Size+Vector3.new(0,0,0.3)
wj.kp4.Size = wj.kp4.Size+Vector3.new(0,0,0.4)
wj.kp5.Size = wj.kp5.Size+Vector3.new(0,0,0.5)
wj.kp6.Size = wj.kp6.Size+Vector3.new(0,0,0.6)
wj.kp7.Size = wj.kp7.Size+Vector3.new(0,0,0.7)
wj.kp8.Size = wj.kp8.Size+Vector3.new(0,0,0.8)
wj.kp9.Size = wj.kp9.Size+Vector3.new(0,0,0.9)
wj.kp10.Size = wj.kp10.Size+Vector3.new(0,0,1)
wj.kp11.Size = wj.kp11.Size+Vector3.new(0,0,1.1)
wj.kp12.Size = wj.kp12.Size+Vector3.new(0,0,1.2)
wj.kp13.Size = wj.kp13.Size+Vector3.new(0,0,1.3)
wj.kp14.Size = wj.kp14.Size+Vector3.new(0,0,1.4)
wj.kp15.Size = wj.kp15.Size+Vector3.new(0,0,1.5)
wj.kp16.Size = wj.kp16.Size+Vector3.new(0,0,1.6)
wj.kp17.Size = wj.kp17.Size+Vector3.new(0,0,1.7)
wj.kp18.Size = wj.kp18.Size+Vector3.new(0,0,1.8)
wj.kp19.Size = wj.kp19.Size+Vector3.new(0,0,1.9)
wj.kp20.Size = wj.kp20.Size+Vector3.new(0,0,2)
wj.kp21.Size = wj.kp21.Size+Vector3.new(0,0,2.1)
wj.kp22.Size = wj.kp22.Size+Vector3.new(0,0,2.2)
wj.kp23.Size = wj.kp23.Size+Vector3.new(0,0,2.3)
wj.kp24.Size = wj.kp24.Size+Vector3.new(0,0,2.4)
wj.kp25.Size = wj.kp25.Size+Vector3.new(0,0,2.5)
wj.kp26.Size = wj.kp26.Size+Vector3.new(0,0,2.6)
wj.kp27.Size = wj.kp27.Size+Vector3.new(0,0,2.7)
wj.kp28.Size = wj.kp28.Size+Vector3.new(0,0,2.8)
wj.kp29.Size = wj.kp29.Size+Vector3.new(0,0,2.9)
wj.kp30.Size = wj.kp30.Size+Vector3.new(0,0,3)
wj.kp31.Size = wj.kp31.Size+Vector3.new(0,0,3.1)
wj.kp32.Size = wj.kp32.Size+Vector3.new(0,0,3.2)

individually naming and writing more code to corespond with each new stage I add is becoming a painstakingly slow process, does anyone know how I can possibly automate this?

1 Like

for loops, you can just iterae through all children of an object, and apply the corresponding data to each of them.

To grab all Children, you would use the Function :GetChildren() on the object you want to grab the children from, you can then utilize the for loop to iterate though the objects, while adding .1 while you iterate:

local children = example:GetChildren() -- grabs all children

-- i means index, it can be the number/order the object is in, or the name of it
-- v means value, what the  index holds


for i,v in children do
    -- this will iterate through all objects in this table, you can then add .1
    -- when you are applying this data, like so:
    x += .1 -- I recommend making a variable prior to looping

    v.Size += Vector3.new(0,0,x) -- adds x to the current value
    -- (x += y) is the exact same as doing (x = x + y) in a simple form
end

However keep in mind that the objects may not be the correct order you want them to be in, so you may need to sort them based on their name, or the number given.

2 Likes

Make the size a variable, then use a for loop and add 0.1 each time.

How will I sort through all of the children of the model that my jumps are in?

1 Like
for i, v in pairs(wj:GetChildren()) do

How would I sort them based on their name?, it has the letters kp with a corresponding numerical digit based on its stage

1 Like

Something like this should work.

local wj = game.Workspace["Lava Wall Jump"]
local size = 0

for i, v in pairs(wj:GetChildren()) do
	v.Size += Vector3.new(0,0,size)
	size += 0.1
end
1 Like

image

Normally it shouldn’t happen, and you wouldn’t need to do this, but if you are using objects that need to be applied in a specific order, then you can do that, as it may be applied incorrectly, however here because they are all in number order, it should work as intended, but if you are applying numbers based off the place they are in (ex: kp30 to kp35), you can take out the kp part of the name, and then divide by 10, which if you have 1, dividing by 10 will have it be 0.1, and so on.

To do this, you can utilize string.sub to take apart the name, and then apply the number, I’ll show you how:

local name = "kp25" -- kp25 is 25th with the parts we have


local x = string.sub(name, 3, #name)
-- string.sub works by cutting off part of the string given, 
-- and returning the result, the first argument is the string
-- you want to change, which here is 'name'
-- The Second is the starting point, which is where we will cut kp
-- we will cut off at character 3 which is "2" in this string
-- this will remove "kp" from the string, the next argument is where
-- we will cut off at the end of the string, which should be the total
-- size of the string, we can get this number by using the # operator on
-- the string, which will return 4 using the current string we have

local increment = x/10

-- here we can divide the number returned by 10, giving us the decimal
-- if you have just a number in the string, lua will use it as a number
-- otherwise it will error

-- we then add the Size
Object.Size += Vector3.new(0, 0, increment)

for this, you should probably use a regular for loop, which is just a single variable counting up (or down)

for i = 1, 10 do
    -- this loop will run 10 times
    -- it starts at 1, and will end at 10

    -- we can use this on a table, by changing 10, to
    -- the number of items in our table, and then using "i"
    -- to get the objects, and apply the correct data

    local v = children[i] -- our part
    local x = string.sub(v.Name, 3, #v.Name) -- gets number from name
    children[i].Size += Vector3.new(0, 0, x/10) -- increments Size
end
2 Likes

Yes, I absolutely loved your commenting, I figured out by doing it this way, it works.

local wallBaseName = "kp"
local wallCount = 30

local x = 0
for i = 1, wallCount do
    local wallName = wallBaseName .. i
    local wall = game.Workspace["Lava Wall Jump"]:FindFirstChild(wallName)

    if wall then
        wall.Size = wall.Size + Vector3.new(0, 0, x)
        x = x + 0.1
    else
        warn("Wall not found:", wallName)
    end
end

I did some more brainstorming with your method, I figured out how to make the obby build its self!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.