You can write your topic however you want, but you need to answer these questions:
I have a script:
-- Initialization
local allBlocks = {}
local Parent = workspace.Folder
for _, starterchild in pairs(Parent:GetChildren()) do
allBlocks[starterchild.Position] = {
f = 0.21,
t = starterchild.Name
}
end
-- BindableEvent listener
script.ManageBlock.Event:Connect(function(position, f, t)
SetValue(allBlocks, position, {f = f, t = t})
end)
-- Function to set value in the table
function SetValue(tbl, key, value)
tbl[key] = {}
tbl[key]["f"] = value.f
tbl[key]["t"] = value.t
end
game:GetService("RunService").Heartbeat:Connect(function()
print(allBlocks[position])
end)
the print(allBlocks[position]) doesnāt print the updated allBlocks[position] because it doesnāt update, I donāt know why (it prints the value from ignition)
I asked chat gpt but it is so stupid, also I rewritted my spaghetti code but still doesnāt work. I already had some dictionary issues in the pastā¦ now itās 3am and Iām becoming angry on my laptopā¦
Thanks you in advance, If u need more information just ask I really need your help.
It will print the same position? Otherwise you cant change the position because that is what you are keying to. You provide a key (i.e. position, so you can find the value, then change the key with the same key!!)
hello, no it doesnāt have to print the position but the f and t values (numbers). The position is the key used for the dictionary. To clarify the issue: when I print allBlocks[position] after SetValue in the BindableEvent, it print the updated value, but when after that I print it in the (āRunServiceā).Heartbeat it prints only the old value. also if I print the value in BindableEvent listener before SetValue it says " attempt to index nil with ātā" or with fā¦ Iām lost
thats exactly the problem. the position is changing, so when you try to access the key it opens a new one. since it does not exist until after the setvalue function (which creates a new index under the new position), it errors.
iow you need to prevent the position of the part from changing.
you can test this by printing the position inside the setvalue and heartbeat functions and im 99% positive it will print different values
also jesus christ you really did just put a print statement in a heartbeat event
yes you were right! thank you! (yeah lol I put a print in hearthbeat but I was at the end of my life after trying to figure out this stupid mistake for like 4 hours and didnāt find any solution )