63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
|
|
import { Players } from "@rbxts/services";
|
||
|
|
import Gameplay_Remotes from "shared/gameplay";
|
||
|
|
|
||
|
|
const sprint = Gameplay_Remotes.Server.Get("Sprint");
|
||
|
|
|
||
|
|
const RunAnim = new Instance("Animation");
|
||
|
|
RunAnim.AnimationId = "rbxassetid://88297455683117";
|
||
|
|
const base_sprint_speed = 16;
|
||
|
|
const sprint_speed = 1.5;
|
||
|
|
const runanim = new Map<number, AnimationTrack>();
|
||
|
|
const isrunning = new Map<number, boolean>();
|
||
|
|
|
||
|
|
Players.PlayerAdded.Connect((player) => {
|
||
|
|
let runningConn: RBXScriptConnection;
|
||
|
|
|
||
|
|
player.CharacterAdded.Connect((character) => {
|
||
|
|
const humanoid = character.FindFirstChildWhichIsA("Humanoid");
|
||
|
|
if (humanoid) {
|
||
|
|
const animator = humanoid.FindFirstChildOfClass("Animator");
|
||
|
|
const anim = animator!.LoadAnimation(RunAnim);
|
||
|
|
anim.Priority = Enum.AnimationPriority.Action;
|
||
|
|
runanim.set(player.UserId, anim);
|
||
|
|
|
||
|
|
runningConn = humanoid.Running.Connect((speed) => {
|
||
|
|
if (isrunning.get(player.UserId)) {
|
||
|
|
if (speed > 2) {
|
||
|
|
if (!anim.IsPlaying) anim.Play(0.2);
|
||
|
|
} else {
|
||
|
|
if (anim.IsPlaying) anim?.Stop(0.2);
|
||
|
|
}
|
||
|
|
} else if (anim?.IsPlaying) {
|
||
|
|
anim?.Stop(1);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
player.CharacterRemoving.Once(() => runningConn.Disconnect());
|
||
|
|
});
|
||
|
|
|
||
|
|
sprint.Connect((player, enabled) => {
|
||
|
|
const character = player.Character;
|
||
|
|
isrunning.set(player.UserId, enabled);
|
||
|
|
if (character) {
|
||
|
|
const humanoid = character.FindFirstChildOfClass("Humanoid");
|
||
|
|
if (humanoid) {
|
||
|
|
if (enabled) {
|
||
|
|
humanoid.WalkSpeed = base_sprint_speed * sprint_speed;
|
||
|
|
// if (humanoid.GetStateEnabled(Enum.HumanoidStateType.Running)) {
|
||
|
|
// const anim = runanim.get(player.UserId);
|
||
|
|
// anim?.Play(0.2);
|
||
|
|
// }
|
||
|
|
} else {
|
||
|
|
humanoid.WalkSpeed = base_sprint_speed;
|
||
|
|
// if (humanoid.GetStateEnabled(Enum.HumanoidStateType.Running)) {
|
||
|
|
// const anim = runanim.get(player.UserId);
|
||
|
|
// anim?.Stop(1);
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|