Hello, I made a little gui to edit stats live, so I can experiment without stopping and starting over and over
Heres what I have:
Everything BUT setting it works
This is the code:
local rs = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local stats = require(rs.modules.shared.stats)
local frame = script.Parent
local new_stat_lbl = frame.New
local path_lbl = frame.Path
local current_lbl = frame.Current
local function calculate_stat(string, new)
local paths = string:split("/")
local instance = stats[player.Character.Name]
local true_path = stats[player.Character.Name]
for _, path in paths do
local result = instance[path]
if result == nil then
return nil
end
true_path = true_path[path]
instance = result
end
if new then
true_path = new
end
return instance
end
path_lbl.FocusLost:Connect(function(enter)
if enter then
local stat = calculate_stat(path_lbl.Text)
if stat then
current_lbl.Text = `Current: {stat}`
else
current_lbl.Text = `Current: {nil}`
end
end
end)
new_stat_lbl.FocusLost:Connect(function(enter)
if enter then
local stat = calculate_stat(path_lbl.Text, new_stat_lbl.Text)
if stat then
current_lbl.Text = `Current: {stat}`
else
current_lbl.Text = `Current: {nil}`
end
end
end)
Anyone know how I can fix this? Im assuming its some indexing error, but im unsure of how to fix it