Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

This is perfect thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.