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.