DevRenix
(renix)
June 27, 2022, 3:22pm
1
My pcall function isn’t with my leaderstats! No output errors
local ClicksDS = game:GetService("DataStoreService"):GetDataStore("ClicksDS")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Clicks = Instance.new("IntValue", leaderstats)
Clicks.Name = "Clicks"
local ClicksData
local Success,Error = pcall(function()
ClicksData = ClicksDS:GetAsync(player.UserId)
end)
if Success then
Clicks.Value = ClicksData
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ClicksDS:SetAsync(plr.UserId, plr.leaderstats.Clicks.Value)
end)
BANSA168
(BANSA168)
June 27, 2022, 3:25pm
2
Wdym? In the title it says “Help with Pcall” and then you say that it’s working?
Qoucx
(Sunken)
June 27, 2022, 3:25pm
3
If it is working why is the title “Help with Pcall”
DevRenix
(renix)
June 27, 2022, 3:28pm
4
I meant isn’t working @bansa168
DevRenix
(renix)
June 27, 2022, 3:33pm
5
I’ve meant to say isn’t working, I had a type. Aplogies
BANSA168
(BANSA168)
June 27, 2022, 3:34pm
6
Can you just print out the ClicksData and tell me what it outputs?
DevRenix
(renix)
June 27, 2022, 3:36pm
7
It prints out as 0, oh wait! I think my stats accidently resetted to 0. I will check if thats the problem.
BANSA168
(BANSA168)
June 27, 2022, 3:37pm
8
In the future make sure you use prints to debug they help a ton with this kinda stuff.
DevRenix
(renix)
June 27, 2022, 3:37pm
9
Yeah, I accidently reset my stats. Although I did print success I never printed ClicksData. Thank you sir.
1 Like
I have some additional details:
in:
game.Players.PlayerRemoving:Connect(function(plr)
ClicksDS:SetAsync(plr.UserId, plr.leaderstats.Clicks.Value)
end)
replace with:
game.Players.PlayerRemoving:Connect(function(plr)
local data = {}
data.Clicks = plr.leaderstats.Clicks.Value
local s, e = pcall(function()
ClickDS:SetAsync(plr.UserId, data) --probably data needs to be a table
end)
if(s) then
print("Succes!")
else
warn("We Didnt Save Because: "..e)
end
end)
DevRenix
(renix)
June 27, 2022, 4:30pm
11
Ive added that already. But however I didn’t use a table/array.