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

How to switch 3 or more values in order?

Asked by 5 years ago

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

Log in to vote
1
Answered by
mc3334 649 Moderation Voter
5 years ago

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
Thank you ! very detailed explaining! Igoralexeymarengobr 365 — 5y
Ad

Answer this question