Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Data Store: Infinite yield possible on...?

Asked by 5 years ago

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

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
5 years ago
Edited 5 years ago

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.

Ad

Answer this question