something i wanted to achieve
local var = "var1"
print(idk) -- idk is i want to print the variable
something i wanted to achieve
local var = "var1"
print(idk) -- idk is i want to print the variable
Why would you want to?
Since there’s no debug.getlocal here I think it’s only possible to do what you want for variables defined globally within a function.
im trying to make a data store system with tables and i need it so i can access it without making more variables
Tables, specifically dictionary tables, were created for this purpose.
One variable that holds key-value pairs is exactly what you’re after.
local DSService = game:GetService(“DataStoreService”):GetDataStore(“Data_Name”)
game.Players.PlayerAdded:Connect(function(PLR)
local uniquekey = “id-”…PLR.UserId
local leaderstats = Instance.new(“Model”, PLR)
local savevalue1 = Instance.new(“NumberValue”, leaderstats)
local savevalue2 = Instance.new(“NumberValue”, leaderstats)
savevalue1.Value = 0
savevalue2.Value = 0
leaderstats.Name = “leaderstats”
savevalue1.Name = “Name1”
savevalue2.Name = “Name2”
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue1.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
else
local NumbersForSaving = {savevalue1.Value, savevalue2.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(PLR)
local uniquekey = “id-”…PLR.UserId
local SaveTable = {PLR.leaderstats[“Name1”].Value, --All in 1 table
PLR.leaderstats[“Name2”].Value
}
DSService:SetAsync(uniquekey, SaveTable)
end)
now i dont need it but instead the script thinks the table is a boolean
Show the script and Ill see if i can figure out the problem
no im doing a new method but its weird now because it prints 3 times
-- Player Data
-- FerbZides
-- August 17, 2020
--[[
Server:
Client:
--]]
local PlayerData = {Client = {}}
local Stats = {
MobControls = {
MobileButton1 = "C";
MobileButton2 = "G";
MobileButton3 = "H";
MobileButton4 = "T";
MobileButton5 = "R"
};
-- FOR THE MY PARK
MyParkData = {
PadName = 0;
CourtName = "COURT_0";
OnSpot = false;
};
-- CUSTOMIZATION
Customization = {
PlayerCustomization = {
Hat1 = "";
Hat2 = "";
Hat3 = ""
};
};
TrailValues = {
IsTrailEnabled = false;
TrailColor = 0;
TrailMode = "Default"
};
}
-- Trails!
local TRAIL_GAMEPASS = false
local TrailId = 0
function PlayerData:Start()
local DataModule = self.Modules.Data
game.Players.PlayerAdded:Connect(function(player)
local data = DataModule.ForPlayer(player.UserId)
local StatsFolder = Instance.new("Folder")
StatsFolder.Parent = player
StatsFolder.Name = "Stats"
local TrailFolder = Instance.new("Folder")
TrailFolder.Name = "TrailInfo"
TrailFolder.Parent = player
local MobControlsFolder = Instance.new("Folder")
MobControlsFolder.Name = "MobileControls"
MobControlsFolder.Parent = StatsFolder
-- ALL STATS IN ONE
for index, MobControls in pairs(Stats.MobControls) do
-- LOAD IT IN
local success, MobControl = data:Get("MobileControl"..index, MobControls):Await()
if (success) then
print("Got Control", MobControl)
else
print("Failed to get stats", MobControl)
end
data:Get("MobileControls"..index, MobControls):Then(function(Value)
if typeof(MobControls) == "string" then
local TypeValue = Instance.new("StringValue", MobControlsFolder)
TypeValue.Name = index
TypeValue.Value = Value
elseif typeof(MobControls) == "boolean" then
local TypeValue = Instance.new("BoolValue", MobControlsFolder)
TypeValue.Name = index
TypeValue.Value = Value
elseif typeof(MobControls) == "number" then
local TypeValue = Instance.new("NumberValue", MobControlsFolder)
TypeValue.Name = index
TypeValue.Value = Value
end
end):Then(function(err)
print("Error: ", err)
end)
end
for _, TrailValues in pairs(Stats.TrailValues) do
-- LOAD AGAIN
local success, TrailColor = data:Get("TrailColor", 0):Await()
local callString, TrailMode = data:Get("TrailMode", "Default"):Await()
if success then
print("Got Value ", TrailColor)
else
print("Failed Value ", TrailColor)
end
if callString then
print("Got Value ", TrailMode)
else
print("Failed Value ", TrailMode)
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
end)
end
function PlayerData:Init()
end
return PlayerData
here is the code
the output for the trails
Got Value 0
Got Value Default Got Value 0
Got Value Default
Got Value 0
Got Value Default
What is this? why is there a string/bool/number value all sharing the same value?
data:Get("MobileControls"..index, MobControls):Then(function(Value)
if typeof(MobControls) == "string" then
local TypeValue = Instance.new("StringValue", MobControlsFolder)
TypeValue.Name = index
TypeValue.Value = Value
elseif typeof(MobControls) == "boolean" then
local TypeValue = Instance.new("BoolValue", MobControlsFolder)
TypeValue.Name = index
TypeValue.Value = Value
elseif typeof(MobControls) == "number" then
local TypeValue = Instance.new("NumberValue", MobControlsFolder)
TypeValue.Name = index
TypeValue.Value = Value
end
that works but the trail values dont work because the looped through table doesn’t work
sorry for the very long bump
i just did leaderstats stuff and it actually worked