You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
To make one _G function to be able to edit one variable using string.split -
What is the issue? Include screenshots / videos if possible!
I’ve created a datastore script with some variables in it, I want to be able to edit all of the variables attached to the user from any script using a global function. The variables are all called “Item” followed by a number. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried just putting 2 strings together then trying to index it, that doesn’t work, I think I know why. Other than that, I don’t have loads of knowledge of scripting
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- The data I'm attempting to refer to
local function NewData()
return {
Item1 = true,
Item2 = true,
Item3 = "string"
}
end
-- How I tried to refer to it
_G.Check = function(Player, ItemNumber)
local VariableName = "Item"..tostring(ItemNumber)
if table.find(ServerData[Player], VariableName) then
return table.find(ServerData[Player], VariableName)
end
end
I hope this makes sense, I understand this isn’t the best coding, but I have to start somewhere.