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

How do I check if a value is in a table?

Asked by 3 years ago
Edited 3 years ago

What I want to do is repeat the RemoteEvent until the CurrentFruit is equal to one of the Fruits in the table. How do I do that?

local fruits = {"Apple", "Orange", "Pineapple"}
local eatevent = game:GetService("ReplicatedStorage").EatEvent
local plr = game.Players.LocalPlayer
local currentfruit = plr.Data.Fruit

repeat
    eatevent:FireServer()
until
currentfruit.Value:lower() == fruits:lower()

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

using table.find(table,value)

so from line 6 to 9, do this:

repeat
    eatevent:FireServer()
until
table.find(fruits,currentfruit.Value)

more abt tables

0
is there any way i could use :lower() on table.find? Velcorii 13 — 3y
0
i don't see a function called :lower(), what is it? NGC4637 602 — 3y
0
its to make strings lowercase for example if i did local text = "WORD" print(text:lower()) then the output would be "word" Velcorii 13 — 3y
0
oh, it is string.lower(text) NGC4637 602 — 3y
View all comments (2 more)
0
however i suggest just changing the uppercases in the table to be lower case >.> and then changing currentfruit.Value into string.lower(currentfruit.Value) NGC4637 602 — 3y
0
thank you very much for telling me! Velcorii 13 — 3y
Ad

Answer this question