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

Can concatenation be used in directories?

Asked by 4 years ago

I'm trying to make a localscript for inventory management of prizes in my game. They are stored on boolvalues in the player and I'm making the inventory buttons only available if they have previously bought it. The problem I'm having is that in order to make the script efficient for all prizes and not have to write down every individual name, I would have to insert the button's name, same as the value's name, into a game directory:

if game:GetService("Players").LocalPlayer ..script.Parent.Name.. Value == true then
    --e
end

Knew from writing it that it wouldn't work. The Value part is thought to be a variable. Is it even possible or does it only work for strings? Is there another solution?

0
Use bracket notation like x[y] to index x with a specific value hiimgoodpack 2009 — 4y
0
I'm dumb I forgot about that SindexMon 6 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hi SindexMon it's a pretty good ideas. Name your button like your items in your storage and just use a loop to find all buttons.

Example with a table for understand.

local newTable = {
    'Item1',
    'Item2',
    'Item3'
}

for index, value in next, newTable do
    print(index, value)
end

OutPut:

1 Item1, 2 Item2, 3 Item3

It's simple and you can do same with a Frame or other. Just put all buttons on a Frame or a Folder and make a Variables linked to this.

Example if you've a ScreenGui named «MenuGui», a Frame put in this ScreenGui, with three buttons named «item1, item2, item3»

local Players = game:GetService('Players') -- Check on your explorer, you can see a folder named «Players». Here is stored all players who play in the server.

local Player = Playes.LocalPlayer -- Possible just on a LocalScript because LocalScript is specified just for the client.

local MenuGui = Player:WaitForChild('PlayerGui') -- StarterGui distribute her childs on all PlayerGui of all Player enter on your game.

for index, value in next, MenuGui.Frame:GetChildren() do
    print(index, value.Name)
end

OutPut:

1 item1, 2 item2, 3 item3

Now if you want you make it buttons clickable or not

for index, value in next, MenuGui.Frame:GetChildren() do
    if data[value.Name] then -- If the bool is true you can click. Otherwise not.
        value.MouseBoutton1Click:Connect(function()
            -- Your code here.
        end)
    end
end

Now you can perfome your script and use fewer lines on your script.

For more question put it below on the commentaries.

Ad

Answer this question