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

How can I find a value from a list of values?

Asked by 10 years ago

I have a script (see below) and I wanted to make it so that if the values name isn't "Fifteen" then it will set the value of that value(?!) to zero.

function onTouch(part)
    if bus:FindFirstChild("Fifteen")then
        bus.Fifteen.Value = bus.Fifteen.Value + 15
    else -- I was thinking you could create a list of all other possible names for the value here and set the value to zero if one of them exists?
    end
end

MD

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

First, make sure bus is defined.

Other than that, I'm not sure what you want.

I'll answer based on what I think you want.

local values = {"","","","","","","",""} --Creates a list of values (make sure you put in the correct names)

function onTouch(part)
    if bus:FindFirstChild("Fifteen")then
        bus.Fifteen.Value = bus.Fifteen.Value + 15
    else 
    for i,v in pairs(values) do --Loop through values
        if bus:findFirstChild(v) then --If the current value exists,
            v.Value = 0 --Set it to 0.
        end
    end
    end
end

0
This is perfect thanks MasterDaniel 320 — 10y
Ad

Answer this question