"Unable to cast value to Object"

I’m making a time convert (minutes to hours, hours to day, etc) and i’m using invoke client because, we can’t use very while loops in a script. and this error i obtain (Unable to cast value to Object (Workspace.Base.Leaderboards.TimePlayed.Main.SurfaceGui.Script’, Line 22 - function format) (obs: i count the lines and it’s in 22, i remove a part of script)

this is my script (not local)

		 local Minutes = val
			 local Hours = 0
			local Days = 0
			local Weeks = 0
			local Months = 0

			if Minutes >= 60 then
				while Minutes >= 60 do --I decided make the first while in this script.--
			    if Minutes >= 60 then
				Hours = Hours +1
				Minutes = Minutes -60
				end
				end
				end		

if Hours >= 24 then
local newDays = game.ReplicatedStorage.convertToDays:InvokeClient(player,Hours,Days) 
Days = newDays
local newHours = Hours - Days *24 --a multiplication to know hours (can return only 1 thing in invoke)-
Hours = newHours
end		

if Days >= 7 then
local newWeek = game.ReplicatedStorage.convertToWeeks:InvokeClient(player,Days,Weeks)
Weeks = newWeek
local newDays = Days - Weeks *7
Days = newDays
end		

if Weeks >= 4 then
				local newMonth = game.ReplicatedStorage.convertToMonths:InvokeClient(player,Weeks,Months)
				Months = newMonth
				local newWeek = Weeks - Months *4
				Weeks = newWeek
			end```


And this is one of my locals scripts

```game.ReplicatedStorage.convertToDays.OnClientInvoke = function(Player,Hours,Days)
	print("convertToDays_client invoked") --not prints guys ;(--
	while Hours >= 24 do
	if Hours >= 24 then
	Days = Days +1
			Hours = Hours -24
		end
	end
	return(Days)
end```

You don’t need to put [NOT SOLVED] in the title. It’s obvious it’s not solved unless you specifically select an answer as the solution.

Please format your code by enclosing the script contents in three backticks ```. This will preserve indentation and use a monospaced font so we can actually read your code and help.

Please can you indicate line 16 in the first script as I suspect you have redacted some of the script making it harder to help you find the issue.

I suspect it’s simply a misunderstanding of how RemoteFunctions work. In the LocalScript, you will only receive two arguments. The first argument you pass on the server side simply tells it which client to invoke - this isn’t passed through to the receiving function. For the example you’ve given, it would be

game.ReplicatedStorage.convertToDays.OnClientInvoke = function(Hours,Days)

I edited and put the three backticks ```. idk how to stop the backticks lol, it’s in the 22 line the error

I believe the backticks need to be on a line of their own, so just add a line break between your last character and the backticks.

In terms of the issue have you corrected all the LocalScripts and if so is it still occurring?

The next likely cause is that player is not actually a Player instance and hence the error of trying to cast the value to an Object.

i’m making a leaderboard and i send the name of player and not the player object, i forgot this, the part of my script with error it’s this: , i’m gonna fix, wait… :

 new.Value.Text = '| '..format(val,name).." hours" --name = PlayerName, not's player object, i'm so dumb ;-;

I see. Yeah, there’s a few things you can do. You can search Players for a player with that name (possibly using FindFirstChild), or you can figure out another way to structure the code to allow you to get the player in the function. Best of luck