Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this method of editing multiple values not work?

Asked by 3 years ago

Ok so I have this code which is meant to edit multiple values inside of multiple models. Im not getting any errors.

This is my code it is a normal script inside of a part in workspace.

function onTouched(part)
    if part.Parent:findFirstChild("Humanoid")~=nil then
        local map = script.Parent.Parent.Parent
        local waves = map.Waves
        print (waves)
        local Wave1 = waves.Wave1:GetDescendants()
        print (Wave1)
        Wave1.Anchored = false
        Wave1.Transparency = 0
        Wave1.Anchored = false
        Wave1.Transparency = 0
        Wave1.Anchored = false
        Wave1.Transparency = 0
        wait (3)
end
end

script.Parent.Touched:connect(onTouched)

Note: The code changes the values multiple times I just added that to make sure that it wasnt the issue which it wasnt.

Is there a better way I can do this or do I have to make edits to my code? Any help is much appreciated!

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

:GetDescendants() returns a table. you will have to use an ipairs loop to loop through the elements of the table and change it.

also, i recommend using :GetChildren() instead of descendants as descendants will return a table of your waves as well as any children that your waves have, which i dont think you want

function onTouched(part)
    if part.Parent:findFirstChild("Humanoid")~=nil then
        local map = script.Parent.Parent.Parent
        for _, wave in ipairs(map.Waves:GetChildren()) do
            wave.Anchored = false
            wave.Transparency = 0
        end
    end
end

script.Parent.Touched:connect(onTouched)

try this

check this out if you wanna learn more about looping thru tables

Ad

Answer this question