Skip to main content

Requests

Messages also allow you to request data from the receiver. In order to do that, we'll utilize a message type called Request. Usually, a function with message type set to Request is suppost to return a value. You can validate a value your message function returns using ValueValidator.

note

Important thing to note is that a value returned by your message function is always promisified. If you return a promise from a function, WCS will use that promise instead.

→ You can read more about promises here.

attack.ts
import { Skill, SkillDecorator } from "@rbxts/wcs";
import { t } from "@rbxts/t";

@SkillDecorator
export class Attack extends Skill {
protected OnStartServer() {
const [worked, value] = this.printSomething().await();
if (worked) print(value);
}

@Message({
Type: "Request",
Destination: "Client",
ValueValidator: t.number,
})
protected async printSomething() {
return math.random(1,5);
}
}
note

The promise returned by a message function can timeout or fail. If arguments are invalid the promise will reject.