'Unable to cast value to Object' Error

So this error keeps popping up:

Setup:

Script

local statsModule = require(script.Parent.Stats)
local remoteEvent = script.Parent:WaitForChild("Events"):FindFirstChild("Loader")

-- // Stats

local startMoney = statsModule.StartMoney

print(startMoney.. "is the current cast for Stonks Builder. (#random > 100, 115)")

remoteEvent:FireClient(startMoney)

Module

local module = {}

module.StartMoney = 1

warn("Using stonks builder.")
return module

When you’re calling :FireClient(startMoney), you’re trying to fire the RemoteEvent on the value stored in the ModuleScript.

However, the first argument will always be a player when calling :FireClient() on a RemoteEvent, as noted by the Documentation on FireClient() from the Roblox Developer Hub.

Hmm, okay lemme see what I can do

Instead of changing the value of the money by doing StartMoney = 1 change it to StartMoney.Value = 1

This is because Value is a property of an Integer, Number, or any value Instance. If you changed StartMoney to 1 instead of it’s value then your making an object a number, not changing its value.

@vf9r That’s false. What you’re talking about only applies to BaseValues, which isn’t the case here.

E.g:

local IntTest = 1
print(IntTest) -- prints 1

Now try to print with .Value

local IntTest = 1
print(IntTest.Value) -- prints nil as .Value doesn't exist

StrongBigeman nailed the issue as the OP forgot to include the player argument in :FireClient() and instead was sending a value.

1 Like

Ah, my bad. Thank you for correcting me, I didn’t read clearly.

1 Like