eRangedJoin Date: 2013-06-15 Post Count: 9746 |
First time using pcall...
local SaveAttemptsLeft = 3 --Attempts it tries to save if failed
local function SaveData()
if SaveAttemptsLeft > 0 then --If didn't try to save 3 times already
local success, message = pcall(DataStore:SetAsync(key, savedData))
if success then
print('Success')
else
SaveAttemptsLeft = SaveAttemptsLeft - 1
SaveData() --Pcalls again attempting to save data
end
end
end
SaveData() --Starts to try to save data
|
|
gskwJoin Date: 2013-01-05 Post Count: 1364 |
No, you're passing the return value of DataStore:SetAsync to pcall()
Do:
local success, message = pcall(function() DataStore:SetAsync(key, savedData) end) |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Like this?
local SaveAttemptsLeft = 3 --Attempts it tries to save if failed
local function SaveData()
if SaveAttemptsLeft > 0 then --If didn't try to save 3 times already
success, message = pcall(function() DataStore:SetAsync(key, savedData)
if success then
print('Save Successful for ' .. player.UserId)
else
SaveAttemptsLeft = SaveAttemptsLeft - 1
SaveData() --Pcalls again attempting to save data
end
end)
end
end
SaveData()
|
|
gskwJoin Date: 2013-01-05 Post Count: 1364 |
You missed the "end)" at the end of the line |
|
gskwJoin Date: 2013-01-05 Post Count: 1364 |
Or rather, you put it in the wrong place. |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
i have a "end)" there
|
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
I'm not getting any errors about the end?
local SaveAttemptsLeft = 3 --Attempts it tries to save if failed
local function SaveData()
if SaveAttemptsLeft > 0 then --If didn't try to save 3 times already
success, message = pcall(function() DataStore:SetAsync(key, savedData)
if success then
print('Save Successful for ' .. player.UserId)
else
SaveAttemptsLeft = SaveAttemptsLeft - 1
SaveData() --Pcalls again attempting to save data
end
end)
end
end
SaveData()
|
|
WoolHatJoin Date: 2013-05-19 Post Count: 1873 |
success, message = pcall(function() DataStore:SetAsync(key, savedData)
if success then
print('Save Successful for ' .. player.UserId)
else
SaveAttemptsLeft = SaveAttemptsLeft - 1
SaveData() --Pcalls again attempting to save data
end
end)
You cannot access what "success" is inside of the pcall itself. You need to decide what to do AFTER you get the results from pcall.
Should be:
success, message = pcall(function() DataStore:SetAsync(key, savedData) end) -- end) moved here
if success then
print('Save Successful for ' .. player.UserId)
else
SaveAttemptsLeft = SaveAttemptsLeft - 1
SaveData() --Pcalls again attempting to save data
end |
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
OH thxs |
|
chimmihcJoin Date: 2014-09-01 Post Count: 17143 |
There is no need to wrap it in a new function.
success, message = pcall(DataStore.SetAsync,DataStore,key, savedData)
|
|
eRangedJoin Date: 2013-06-15 Post Count: 9746 |
Chim how would I put it inside the function, it keeps giving me errors:
This is what I got for now.
local SaveAttemptsLeft = 3 --Attempts it tries to save if failed
local function SaveData()
if SaveAttemptsLeft > 0 then --If didn't try to save 3 times already
success, message = pcall(function() DataStore:SetAsync(key, savedData) end)
if success then
print('Save Successful')
else
SaveAttemptsLeft = SaveAttemptsLeft - 1
SaveData() --Pcalls again attempting to save data
end
end
end
SaveData()
|
|