Usermessage giving the wrong value.

Serverside I have something such as :
[lua]function meta:UpdateMoney(amount)
self.Money = amount
SendUserMessage(“ClientMoneyUpdate”, self, amount) – Notify the client their money has changed.
print("Sent : "…amount)

Clientside I have this :
[lua]local function ClientMoneyUpdate( um )
LocalPlayer().Money = um:ReadShort()
print("Got: "…LocalPlayer().Money)
usermessage.Hook(“ClientMoneyUpdate”, ClientMoneyUpdate)[/lua]

The problem only occurs the first time the usermessage is sent, which is in PlayerInitialSpawn.
In this case it just so happens to send the value 1337:ninja: serverside and retrieves the value 26210 clientside.

What gives?


How comes? I am using the data sent by the server. There is no other number around at this time. Also any subsequent usermessage behaves properly and receives the value sent by the server.


That’s probably stupid, but what happens if you send the value as Int instead of Short?
Also, try storing um:ReadShort() into a local variable, and then print that variable. LocalPlayer() has a kinda weird behaviour sometimes, at least for me.

SendUserMessage() sends Longs not Shorts.

Oh, true that, I didn’t even notice he used SendUserMessage. :v:
Yeah, avoid using that function whenever you need to send values and stuff like that.

SendUsermessage() is a default function?

But it’s also a convenience function that doesn’t know how big the numbers you use are, so it sends the biggest type possible. (I think)

I’ll try sending a regular usermessage asap.


Well sending the value as a Short fixed the issue, but gave me a new and unrelated(?) one.

LocalPlayer().Money = um:ReadShort()

It prints :


Nevermind that was a silly error. Removing the print obviously fixed it.:3: