Very quick question on a script

  1. What do you want to achieve?
    I have a question on this part of my script. How can I make the variable into the script? (It’s a simplified version of my script)

  2. What is the issue?
    I don’t know how to do that.

local d = "c"

a.b.[d].Value = true
3 Likes

No, my script shows a path to a value and then I have the variable with the name of the value (the name may differ). And I don’t know how to include the variable in the path to the value.

Alright, this is very simple, let’s say:

A is a table and b is a table in A and there is a Boolean value in B, D is a string used to reference said value.

local A = {
B = {[‘LOL’] = BooleanValue}
};

local D = ‘LOL’;

A.B[D].Value = true;
print(A.B[D].Value);

This should print true

Maybe these [] are confusing to you?

I’m not sure I understood the question, so you want to have a variable with said value of A.B[D].Value ?

Because if you want to have a variable outside the table with the value of A.B[D].Value ,
just do:

local value = A.B[D].Value
local c = "b"

a..c..Value = true

-- This should be the same as

a.b.Value = true

But I don’t have a table.
Wait. I will try to explain it more

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(ItemName, LocalPlayer)
	LocalPlayer.ShopItems.ItemName.Value = true
end)

This is the (shortened) script. But the IntValue isn’t called ItemName. The script should take the name defined by the variable ItemName instead of the string “ItemName”.

Are you trying to do this:

local C = ‘Hello’

print(C..’ World’)

should print ‘Hello World’

So you want to find a child of an instance using a string?

1 Like

Yes, kind of. I don’t have it in a print thing and I have the variable between a path to a value

Yes

This text will be blurred

local String = ‘Lol’

local Value = _Path:FindFirstChild(String)

If Value then
Value.Value = true
else
return
end;
1 Like

When you tried the original code, what did it print?

Yes, this should work thank you!

LocalPlayer.ShopItems:FindFirstChild(ItemName).Value = true

It wouldn’t print anything, because there’s no print(), but it would put an error, because theres no child called ItemName.

Yeah I meant what did the output print, also unless you are guaranteed the item exists you need to include an if statement or else you will get an error (said item doesn’t exist)

local Item = _Path:FindFirstChild(String)

if Item then
Item.Value = true
end;

Also if my code worked, you should select it as the solution.

1 Like