Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Data Store: Infinite yield possible on...?

Hai. This is the script:

local playeractive = false
local statsDS = game:GetService("DataStoreService"):GetDataStore("StoreName")
local prefix = "usr_"

game.Players.PlayerAdded:Connect(function(plr)
    local points = plr:WaitForChild("Backpack").AvailablePoints
    local strength = plr:WaitForChild("Backpack").Strength
    -- load data in
    local data = statsDS:GetAsync(prefix .. tostring(plr.UserId))
    if data then
        print("Data loaded for " .. prefix .. tostring(plr.UserId))
        points.Value = data[1]
        strength.Value = data[2]
    end

    points.Parent = plr
    strength.Parent = plr 
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local data = {
        plr.Backpack:WaitForChild("AvailablePoints").Value,
        plr.Backpack:WaitForChild("Strength").Value
    }
    -- pass a table to save
    statsDS:SetAsync(prefix .. tostring(plr.UserId), data)
end)

game:BindToClose(function()
	for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
	    local data = {
	        plr.Backpack:WaitForChild("AvailablePoints").Value,
	        plr.Backpack:WaitForChild("Strength").Value
	    }
		print("Data save exit is ", unpack(data))
	    -- pass a table to save
	    statsDS:SetAsync(prefix .. tostring(plr.UserId), data)
	end
end)


local event = game.ReplicatedStorage.Erasure.RemoteEvent

event.OnServerEvent:Connect(function(plr)
          local data = {
        plr.Backpack:WaitForChild("AvailablePoints").Value,
        plr.Backpack:WaitForChild("Strength").Value
    }
    -- pass a table to save
    statsDS:SetAsync(prefix .. tostring(plr.UserId), data)
end)


My only problem is at line 46, and at every plr.Backpack:WaitForChild("X").

Once finished this, I'll finally be done with Data Storage, could you help me for the last time? (Or that is what I hope.)

ERROR:

Infinite yield possible on 'Players.Myname.Backpack:WaitForChild("AvailablePoints") Stack begin Script 'ServerScriptService', Line 46 Stack end

_

1 answer

✓ Accepted answer

it is not an error, it is a warning saying that the WaitForChild is able to last forever, this warning pops up after a certain amount of time after the object you are waiting on doesn't appear. you don't have to worry about this.

for the same reason stated above, if it does pop up and it's not supposed to it's because the item you are waiting for simply won't appear, you either misspelled it or the parent is wrong.

This discussion is preserved as it was. New answers, comments, and votes are closed.