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

Changed connection issues?

The output doesn't say anything and loc is a "Number Value". btw the only run#() that exists is runA(). If that's the problem. plz let me know

loc.Changed:connect(function()
	if loc.Value == 1 then runA()
	elseif loc.Value == 2 then runB()
	elseif loc.Value == 3 then runC()
	elseif loc.Value == 4 then runD()
	elseif loc.Value == 5 then runE()
	elseif loc.Value == 6 then runF()
	elseif loc.Value == 7 then runG()
	elseif loc.Value == 8 then runH()
	elseif loc.Value == 9 then runI()
	elseif loc.Value == 10 then runJ()
	elseif loc.Value == 11 then runK()
	elseif loc.Value == 12 then runL()
	elseif loc.Value == 13 then runM()
	elseif loc.Value == 14 then runN()
	elseif loc.Value == 15 then runO()
	elseif loc.Value == 16 then runP()
	elseif loc.Value == 17 then runQ()
	elseif loc.Value == 18 then runR()
	elseif loc.Value == 19 then runS()
	elseif loc.Value == 20 then runT()
	elseif loc.Value == 21 then runU()
	elseif loc.Value == 22 then runV()
	elseif loc.Value == 23 then runW()
	elseif loc.Value == 24 then runX()
	elseif loc.Value == 25 then runY()
	end
end)

3 comments

0

You need to provide more information. Like what is in the output? What is this script supposed to do?

0

Does the runA() function execute?

0

not when the function is set to "Changed" event. But if I make it while true do, it will execute. I think i know the problem. Changed only has to do with instances and cannot be triggered by values

1 answer

✓ Accepted answer

You can test to see if the function is running by adding a print statement:

loc.Changed:connect(function()
	print("loc Changed. Current value:", loc.Value)
	--rest of function here
end)

Certainly, if your code only has "RunA" but is going to try and call "RunB", "RunC", etc, that's a problem. If you only want one function, use an argument instead, like:

function Run(letter)
	--do something with letter here
end
loc.Changed:connect(function()
	if loc.Value >= 1 and loc.Value <= 25 then
		local letter = string.char(64+loc.Value) --will return 'A' if loc.Value is 1, 'Y' if loc.Value is 25
		Run(letter)
	end
end

If you want 25 different functions, you can make the loc.Changed function run faster by using a function lookup table:

runFunctions = {
runA, runB, runC, runD, ---etc
}
loc.Changed:connect(function()
	if loc.Value >= 1 and loc.Value <= 25 then
		runFunctions[loc.Value]() --access the desired function and then the '()' part calls it
	end
end

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