Unable to cast value to Object - trying to make a "days until" counter

Okay, so I am creating a counter for the amount of days until Christmas, and this is the code I managed to get:

date = os.time{day=25,year=2018,month=12}
today = os.difftime(os.time() - 18000, date)/(24*60*60)
wholedays = math.floor(today) * -1

When I print the variable “wholedays” it does print 30 as expected, since at the time of writing this it is 30 days until the 25th of December.

However, when I try to use it in my event:

game:GetService("ReplicatedStorage").days:FireClient(wholedays)

(the code for the event is

game:GetService("ReplicatedStorage").days.OnClientEvent:Connect(function(daystill)
script.Parent.Text = daystill
end)
)

I get this error:

Unable to cast value to Object
17:03:33.179 - Stack Begin
17:03:33.179 - Script ‘ServerScriptService.countdownHandler’, Line 6
17:03:33.180 - Stack End

I might just be really dumb, but I can not see why I keep getting this error.

UPDATE
I just realized, I was called :FireClient instead of :FireAllClients, it works now.

6 Likes

:FireClient takes at least one parameter (the player to fire the event to) alongside additional others.

RemoteEvent:FireClient(game.Players.RedDuck765, otherParameter)

The reason :FireClient was erroring was because you weren’t parsing the player.
:FireAllClients works because it sends the values to every player without you needing to input any player’s name.

13 Likes

I solved this issue, I realized I was calling :FireClient on the event instead of :FireAllClients like I meant to!

16 Likes

You may want to do this exclusively on the client instead of sending it from the server as the timezone of the server won’t necessarily be in the same as the client.

A better way to do this is with os.date using !*t as the format string to get the local time and checking the yday in the dictionary it returns.

1 Like