Why isn't this working?

Not sure. I think it should work, but it doesn’t seem to, also, I cannot find anything that would help

		if Success then
			if InstanceHolder:GetAttribute(ValueName.."CanUpdate") == nil then
				CurrentSavesHold += 1
				InstanceHolder:GetPropertyChangedSignal(ValueName):Connect(function()
					local GetService = ServerStorage:WaitForChild("SaveService")
					local GetFullName = InstanceHolder:GetFullName()
					local Amount = #GetFullName
					for i = 1, Amount, 1 do
						local Check = GetService:FindFirstChild(GetFullName[i])
						print(Check)
					end
		
				end)
			end
		else
			warn(ErrorMsg)
		end

The error:

Argument 1 missing or nil - Server - SaveService:209

I don’t know yet because which line is line 209?

2 Likes

GetFullName doesn’t return a table; it returns a string of the object and its ancestors separated by periods, so trying to find a specific entry of it will return nil. If you want to make a table, you can use string.split to break up the string by periods:
local GetFullName = string.split(InstanceHolder:GetFullName(), ".")

https://developer.roblox.com/en-us/api-reference/function/Instance/GetFullName

1 Like

MY BAD. I meant to split it. I think that might be the issue.

Now, the new code is this:

if Success then
			if InstanceHolder:GetAttribute(ValueName.."CanUpdate") == nil then
				CurrentSavesHold += 1
				InstanceHolder:GetPropertyChangedSignal(ValueName):Connect(function()
					local GetService = ServerStorage:WaitForChild("SaveService")
					local GetFullName = InstanceHolder:GetFullName()
					print(GetFullName)
					local SplitName = string.split(tostring(GetFullName), ".")
					local Amount = #SplitName
					local Save
					print(Amount)
					for i = 1, Amount do
						local Check = GetService:FindFirstChild(SplitName[i])
						Save = Check
					end
					local CheckForValue = Save:FindFirstChild(ValueName.."Save")
					print(CheckForValue)
					if CheckForValue then
						InstanceHolder[ValueName] = CheckForValue.Value
						else warn("Uh oh!") 
					end
				end)
			end
		else
			warn(ErrorMsg)
		end

The new error:

17:35:42.053 ServerScriptService.SaveService:216: attempt to index nil with ‘FindFirstChild’ - Server - SaveService:216

That means that one of the objects you’re using FindFirstChild on is nil. You call FindFirstChild on two lines, though I will assume this one is the one causing the error:

This would mean Save is nil, which in turn would mean GetService doesn’t have a direct child that’s named after one of the elements in the hierarchy of InstanceHolder.

With what I currently know about the problem, my questions are:

  • GetFullName includes the name of the object it was used on at the end of the string. Was this intended in your code?

Since it’s always the last element in the table, you can get around it by changing the beginning of your for loop to for i = 1, Amount - 1 do.

  • Did you mean to make GetService:FindFirstChild(SplitName[i]) recursive (meaning it searches through all descendants of GetService instead of only immediate children)?

Changing this to GetService:FindFirstChild(SplitName[i], true) will make it recursive.

This could get it mixed up with another folder, though.

Since I’m not sure what the exact descendants of GetService are, what I said there may not apply to your situation.

Is the object that Save is trying to access a direct child of GetService or is it under any folders? Have you made sure that there are children of GetService that are named after every element of SplitName?

I don’t think you understand. That’s probably the best method, there is pretty much a guarantee that there is another descendant by the same name.

Decided to run this in Studio and see what I got.
Screen Shot 2022-01-31 at 11.50.43 PM
I was able to get the script to work with this hierarchy, using a part named InstanceHolder in the workspace as InstanceHolder and “Name” as ValueName. My best guess at this point is that the folders named after the elements of SplitName[i] are either misplaced or nil at the time that the script tries to find them. It may be a good idea to verify that Save exists later in the script.

No. Everything is ready and exists. I even added a system to ensure it. Please make sure your staying on topic. It’s nothing to do with waiting, it’s to do with the GetFullName part, and the for loop. This is what the for loop is getting from it:
image

If that’s what the for loop is printing, then your code is setting the Save variable to nil on the second and third iterations of the loop, guaranteeing that Save will be nil on the next line.

I don’t know what you’re trying to do with this code, but I would:

  • Add an if statement inside the loop to check if FindFirstChild() returned something, in which case I would assign that find result to the Save variable. I would also put in a break statement to stop the loop after that.
  • Add an if statement to verify that Save is not nil, since the loop seems like it isn’t guaranteed to find anything.
1 Like

I don’t really understand. Are you able to provide a fix? all of this has been attempted behind this. None of it works.

Your loop is setting the Save variable to nil, which breaks the code. To fix this, you need to 1. Stop setting it to nil, and 2. Ensure Save exists before doing anything

for i = 1, Amount do
    local Check = GetService:FindFirstChild(SplitName[i])
    if Check then
        Save = Check
        break
    end
end

if Save then
    -- execute the rest of your code
else
    -- handle the case where Save is nil
end

2 Likes

Still isn’t working, the entire function:

function Save.SaveValue(InstanceHolder, ValueName) 
	if CurrentSavesHold <= 0 then 
		local Success, ErrorMsg = pcall(function()
			local Test = InstanceHolder:GetPropertyChangedSignal(ValueName):Connect(function() end)
			Test:Disconnect()
		end)
		if Success then
			if Success then
				if InstanceHolder:GetAttribute(ValueName.."CanUpdate") == nil then
					CurrentSavesHold += 1
					InstanceHolder:GetPropertyChangedSignal(ValueName):Connect(function()
						local GetService = ServerStorage:WaitForChild("SaveService")
						local GetFullName = InstanceHolder:GetFullName()
						print(GetFullName)
						local SplitName = string.split(tostring(GetFullName), ".")
						local Amount = #SplitName
						local Save
						print(Amount)
						for i = 1, Amount do
							local Check = GetService:FindFirstChild(SplitName[i])
							if Check then
								Save = Check
								break
							end
						end

						if Save then
							local Value = Save:FindFirstChild(ValueName.."Save")
							InstanceHolder[ValueName] = Value.Value
						else
							warn("Could not return to normal!")
							return false
						end
					end)
				end
			end
		else
			warn(ErrorMsg)
		end
	end
end

Sill cant seem to find a breaking point which would break the script entirely. It may look like the for loop, but it doesn’t even reach it.

Try using the Debugger to see where your code logic stops and why.

Or if you’re not familiar with the debugger, print out the contents of each if conditional to see if it’s true. If it’s not true, find out why.

1 Like

Okay, I will try. It appears to be conditional I suppose.