New TextChatService Frustrations

Hi there, Developers! It’s Shiloh again.

I’m have some frustrations with the new textchatservice. Scripting on it is very difficult for me, and AI seems to not have fully adapted to the change yet.

I tried to make a script where if someone says /e (prefix) then an animation name in my table, then play that animation that contains an rbxassetid animation. The script has no errors, but doesn’t work either…

Here is the script:

-- !shiloh

local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local LocalPlayer = Players.LocalPlayer

local animations = {
	
	qb = "rbxassetid://109353950259313"
	
}

local currentTrack = nil
local moveConn = nil

TextChatService.OnIncomingMessage = function(message)
	if message.TextSource then
		local sender = Players:GetPlayerByUserId(message.TextSource.UserId)
		
		if sender == LocalPlayer then
			local msg = message.Text
			
			if msg:sub(1, 3):lower() == "/e" then
				local animName = msg:sub(4):lower()
				local animId = animations[animName]
				
				if animId then
					if currentTrack then
						currentTrack:Stop()
						currentTrack = nil
					end
					
					local char = LocalPlayer.Character
					local humanoid = char:WaitForChild("Humanoid")
					
					local anim = Instance.new("Animation")
					anim.AnimationId = animId
					
					currentTrack = humanoid:LoadAnimation(anim)
					currentTrack:Play()
					
					if moveConn then moveConn:Disconnect() end
					
					moveConn = humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
						if humanoid.MoveDirection.Magnitude > 0 then
							if currentTrack.IsPlaying then
								currentTrack:Stop()
								currentTrack = nil
							end
							
							moveConn:Disconnect()
							moveConn = nil
						end
					end)
				end
			end
		end
	end
end

Please help if you can, this script goes in starterplayerscripts.

When you say the code is in a script, do you mean a Script or a LocalScript? In order for the variable LocalPlayer to be non-nil, the code would have to be in a LocalScript. It may help narrow down the issue by adding some prints inside each of the nested conditionals to ensure code is running and determine where it is getting to in the logic.

This is a local script in side of starterplayerscripts, that doesn’t work by the way.