Script problem!

  1. What do you want to achieve?
    I want to know what is the problem with this script !
  2. What is the issue?
    When I try to save the data the success of the pcall() return false …
  3. 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)

Thanks you for the help and have a nice day !

Could you say what exactly transfers the data as “Time” or could you possibly show me the script?

1 Like

I don’t understand sorry, can you reformulate please ?

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)

1 Like

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

What exactly do you want to achieve with your script?

1 Like

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 … :sob::joy:

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)
1 Like

Thanks you very much for your help but it does not work … :confused:

what did it print in the output?

1 Like

It print this :
WARNING: COULD NOT SAVE PLAYER DATA: 103: string is not allowed in data stores.

I think there is a different way to engage because it’s an ordered data !

1 Like

The error cleary says you whats wrong here. I think the Time are numbers, but you store them as strings. Add this function to your local script:

RemoteEvent3:FireServer(tonumber(TextLabel.Text))

instead of

RemoteEvent3:FireServer(TextLabel.Text)
1 Like

Ah I understand i’m so stupid thank you very much !!!

So I have do this :

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)

try if it works and you will see

1 Like

Yes it’s work perfectly !
Thank you so much !!!

no problem. You can mark it as the solution for for people who had the same problem as you :smiley:

1 Like

It’s already done !

ezegjzgjeigzjgzeg

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.