What do you want to achieve?
I want to know what is the problem with this script !
What is the issue?
When I try to save the data the success of the pcall() return false …
What solutions have you tried so far?
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GlobalRanking = DataStoreService:GetOrderedDataStore("GlobalRanking")
local RemoteEvent = ReplicatedStorage.Finish
RemoteEvent.OnServerEvent:Connect(function(Player, Time)
local Success, CurrentGlobalRanking = pcall(function()
return GlobalRanking:GetAsync(Player.UserId)
end)
if CurrentGlobalRanking == nil then
local Success = pcall(function()
GlobalRanking:SetAsync(Player.UserId, Time)
end)
print(Success) --False--
else
if CurrentGlobalRanking > Time then
local Success = pcall(function()
GlobalRanking:SetAsync(Player.UserId, Time)
end)
end
end
end)
You have to fire the event for it to work right? If you use the :SetAsync function you also use the “Time” instance. Could you show me the local script which transfers this value (the function that should fire the remote event should look like this: RemoteEvent:FireServer(Time)
Yes, I send you the local script but I think the error is located at the SetAsync() where I have maybe make a mistake :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.StartTimer
local RemoteEvent2 = ReplicatedStorage.StopTimer
local RemoteEvent3 = ReplicatedStorage.Finish
local Players = game.Players
local Player = Players.LocalPlayer
local TextLabel = script.Parent.TextLabel
local Sec = 0
local Min = 0
local Started = false
local Finish = false
local v = 0
RemoteEvent.OnClientEvent:Connect(function()
TextLabel.TextTransparency = 0
v += 1
if tostring(Player.Team) == "1" then
if v > 1 then
TextLabel.Text = "0:00"
Sec = 0
Min = 0
v = 1
Started = true
else
Started = true
end
end
end)
RemoteEvent2.OnClientEvent:Connect(function()
if Started then
Finish = true
RemoteEvent3:FireServer(TextLabel.Text)--HERE--
end
end)
while wait(1) do
if Started and not Finish then
if Sec < 59 then
Sec += 1
if Sec >= 10 then
TextLabel.Text = Min..":"..Sec
else
TextLabel.Text = Min..":0"..Sec
end
else
Sec = 0
Min += 1
TextLabel.Text = Min..":00"
end
end
end
I want to save the data of the players “Time” in an ordered data but when I print if the saving was a success that return me false but I don’t any mistakes in the saving, and there’s no error in the output …
I’m lost …
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GlobalRanking = DataStoreService:GetOrderedDataStore("GlobalRanking")
local RemoteEvent = ReplicatedStorage.Finish
RemoteEvent.OnServerEvent:Connect(function(Player, Time)
local Key = "Player_"..Player.UserId
local succes, err = pcall(function()
GlobalRanking:SetAsync(Key, Time)
end)
if err then
warn('WARNING: COULD NOT SAVE PLAYER DATA: '..err)
end
end)
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GlobalRanking = DataStoreService:GetOrderedDataStore("GlobalRanking")
local RemoteEvent = ReplicatedStorage.Finish
RemoteEvent.OnServerEvent:Connect(function(Player, Time)
local Time = tonumber(string.split(Time, ":")[1])*60 + tonumber(string.split(Time, ":")[2])
local Success, CurrentGlobalRanking = pcall(function()
return GlobalRanking:GetAsync(Player.UserId)
end)
if CurrentGlobalRanking == nil then
local Success = pcall(function()
GlobalRanking:SetAsync(Player.UserId, Time)
end)
print(Success)
else
if CurrentGlobalRanking > Time then
local Success = pcall(function()
GlobalRanking:SetAsync(Player.UserId, Time)
end)
end
end
end)