Hi, i want make datastore using pcall function pls help script:
local DataStoreService = game:GetService("DataStoreService")
local Goldtraildatastore = DataStoreService:GetDataStore("GoldTrailDatastore")
game.Players.PlayerAdded:Connect(function(Player)
local GoldTrail = Instance.new("IntValue")
GoldTrail.Parent = Player:WaitForChild("Trails")
GoldTrail.Name = "GoldTrail"
GoldTrail.Value = 0
local Data = Goldtraildatastore:GetAsync(Player.UserId)
if Data then
GoldTrail.Value = Data
end
end)
--------------------------------Autosaving part----------------------------------------
game.Players.PlayerRemoving:Connect(function(Player)
Goldtraildatastore:SetAsync(Player.UserId, Player.Trails.GoldTrail.Value)
end)
local DataStoreService = game:GetService("DataStoreService")
local Goldtraildatastore = DataStoreService:GetDataStore("GoldTrailDatastore")
game.Players.PlayerAdded:Connect(function(Player)
local GoldTrail = Instance.new("IntValue")
GoldTrail.Parent = Player:WaitForChild("Trails")
GoldTrail.Name = "GoldTrail"
GoldTrail.Value = 0
local success,err = pcall(function()
Goldtraildatastore:GetAsync(Player.UserId)
end)
if Data then
GoldTrail.Value = Data
end
end)
--------------------------------Autosaving part----------------------------------------
game.Players.PlayerRemoving:Connect(function(Player)
Goldtraildatastore:SetAsync(Player.UserId, Player.Trails.GoldTrail.Value)
end)
local DataStoreService = game:GetService("DataStoreService")
local Goldtraildatastore = DataStoreService:GetDataStore("GoldTrailDatastore")
game.Players.PlayerAdded:Connect(function(Player)
local GoldTrail = Instance.new("IntValue")
GoldTrail.Parent = Player:WaitForChild("Trails")
GoldTrail.Name = "GoldTrail"
local Success, Error
Success, Error = pcall(function()
Data = Goldtraildatastore:GetAsync(Player.UserId)
end)
if Success then
if Data then
GoldTrail.Value = Data
print("Loaded "..Player.UserId)
else
GoldTrail.Value = 0
print(Player.Name.." is new to the game")
end
else
print(Error)
end
end)
--------------------------------Saving part----------------------------------------
game.Players.PlayerRemoving:Connect(function(Player)
local success, errorMsg
success, errorMsg = pcall(function()
Goldtraildatastore:SetAsync(Player.UserId, Player.Trails.GoldTrail.Value)
end)
if success then
print("Saved "..Player.UserId)
else
print(errorMsg)
end
end)
local DataStoreService = game:GetService("DataStoreService")
local Goldtraildatastore = DataStoreService:GetDataStore("GoldTrailDatastore")
game.Players.PlayerAdded:Connect(function(Player)
local GoldTrail = Instance.new("IntValue")
GoldTrail.Parent = Player:WaitForChild("Trails")
GoldTrail.Name = "GoldTrail"
GoldTrail.Value = 0
local Data = Goldtraildatastore:GetAsync(Player.UserId)
if Data then
GoldTrail.Value = Data
end
end)
--------------------------------Autosaving part----------------------------------------
game.Players.PlayerRemoving:Connect(function(Player)
local Success,Fail = pcall(function()
Goldtraildatastore:SetAsync(Player.UserId, Player.Trails.GoldTrail.Value)
end)
if Fail then
Goldtraildatastore:SetAsync(Player.UserId, Player.Trails.GoldTrail.Value)
end
end)