im trying to make a simple data saving function though it stops at the pcall. when printing statements the script will print “repeating” but will not advance to print “finished pcall”. I think that the pcall is holding up the script but i have no clue why or how to fix the issue
ive tried looking on the devforum but the pcall does not yield any errors but instead yields the script infinitely
Edit: the problem is the :SetAsync() function of my datastore that causes an infinite yield
have you tried just doing local success, message = pcall, instead of defining both sucess and message first? im not familiar with pcalls, but i think you do it all in one line, like this
local success, errorMessage = pcall(function()
--code
end)
local function safecall(ac, f, ...)
local s,e,try = nil,nil,1
while try < ac+1 do
s,e = pcall(f, ...)
if s then
break
end
warn(e)
try = try + 1
task.wait(--[[enter wait time here]])
end
end
--example usage
safecall(1, function()
end)
I tried to remake the function tell me if this one works
This function should work the same as your current one, but without the yielding issue:
local function save_player_data(player, attempts)
local attempts = attempts or 5
if sessionData[player.UserId] then
local success, message = pcall(playerDataStore.SetAsync, playerDataStore, player.UserId, sessionData[player.UserId])
if success then
print("Data saved for "..player.Name)
else
if attempts > 0 then
task.wait(3)
save_player_data(player, attempts - 1)
else
warn("Unable to save for "..player.Name)
end
end
end
end
You can optionally add a number value as the second argument if you decide to change the number of attempts in the future