Custom /e commands

Not sure if this was what you meant.
image

I tried to remake it and I came up with this:

wait(1)

local player = game:GetService('Players').LocalPlayer
local Player = game.Players.LocalPlayer

local vCharacter = Player.Character
local myHumanoid = vCharacter:WaitForChild("Humanoid")


local playing = false

cooldown = 0

local emotes = {
	HandsUp = {myHumanoid:LoadAnimation(script.HandsUp),"Hands",8},
	Detained = {myHumanoid:LoadAnimation(script.Detained),"Detain",8}
}

function ResetAll()
	for i,v in pairs(emotes)do
		v[1]:Stop()
		myHumanoid.WalkSpeed = 16
	end
end

player.Chatted:connect(function(message)
	if cooldown > 0 then return end
	for i,v in pairs(emotes) do
		if message:sub(1,3) == "/e " then
		if message:sub(4) == v[2] then
			if playing == false then
				emote:Play()
				myHumanoid.WalkSpeed = v[3]
				playing = true
				script:WaitForChild("enabled").Value = playing
				script.AnimateEvent:Fire("Animate", true)
			elseif playing == true then
				ResetAll()
				playing = false
				script:WaitForChild("enabled").Value = playing
				script.AnimateEvent:Fire("Animate", false)
			end
			cooldown = 3
		end
	end
end

But that doesn’t work either. What have I done wrong? How do I fix it?
This is how it looks like. image

1 Like

Yes that’s… what I said. There isn’t a real need to add a preload to this function and especially what was initially suggested.

LoadAnimation takes an Animation object and prepares it to be used by humanoids (generates an AnimationTrack object).

1 Like

I’m still a bit confused…
Could someone explain in details how to fix it or give an example?

1 Like

Sorry for not replying earlier, heres the fix.
In the loop settings the emotes table, it wasn’t loading animation on the humanoid, but it guesses that the animation is loaded when typing emote.

It would look something like this in the end:

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild('Humanoid')

local emotes = {
 hands_up = "rbxassetid://0000"
};

for i,v in pairs(emotes) do
 local anim = Instance.new('Animation')
 anim.AnimationId = v
 emotes[i] = humanoid:LoadAnimation(anim)
end

player.Chatted:connect(function(message)
 if message:sub(1,3) == "/e " then
  local emote = message:sub(4)
  emote = emotes[emote]
  if emote then
   if emote.IsPlaying then emote:Stop() else emote:Play() end
  end
 end
end)
3 Likes

the last end need to be end)
end

so it will be this:

player.Chatted:connect(function(message)
 if message:sub(1,3) == "/e " then
  local emote = message:sub(4)
  emote = emotes[emote]
  if emote then
   if emote.IsPlaying then emote:Stop() else emote:Play() end
  end
 end
end)

because :Connect(function(message) need a end) and not a end