Skip to main content

Start an ability

Let's bind our ability start to some user input. To achieve this, we need to modify our client.ts file, so that it could listen to user input and start the skill we need.

Then, when a user makes an input it should get the replicated character wrap, get the skill and request the launch by calling Start.

client.ts
import { Players, UserInputService } from "@rbxts/services";
import { Character } from "@rbxts/wcs";
import { Attack } from "shared/skills/attack";

// get the replicated character wrap of local player's current character
function getCurrentWCS_Character() {
const characterModel = Players.LocalPlayer.Character;
if (!characterModel) return;

return Character.GetCharacterFromInstance(characterModel);
}

UserInputService.InputBegan.Connect((Input, GameProcessed) => {
if (GameProcessed) return;
if (Input.UserInputType === Enum.UserInputType.MouseButton1) {
// get and start the "attack" when we left click
const character = getCurrentWCS_Character();
character?.GetSkillFromConstructor(Attack)?.Start();
}
});
note

Remember that if you request an action like Start or End on client, it will just make a remote request to server for it to perform the action.