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

How to switch 3 or more values in order?

So lets suppose i have a meta table

local tablevalues = {"A","B","C"}
local value = nil

so i wanted to know how could i switch these values in order for example when a keyboard key is pressed, i want to change value to one of these tablevalues value correctly in order, can someone help me? i am stil llearning meta tables...

1 answer

✓ Accepted answer

Modify your script to this:

local tablevalues = {"A","B","C"}
local NextTable = 1

game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
	print(tablevalues[NextTable])  --printing the next data val
	if NextTable == #tablevalues then --Checking if this is the last value of the table and we need to go back to pringing number 1
		NextTable = 1 --Saying we need to go back to printing #1
	else
		NextTable = NextTable+1 --If its not the last value, advance to the next value.
	end
end)

This will work with as many values as you put in that table. You can keep adding if you desire. With further questions/comments/concerns, feel free to reply to my answer. Happy scripting! ~mc3334

1 comment

1

Thank you ! very detailed explaining!

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