So im making a Eternal Towers Of Hell fangame, and i made a emote
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local animationId = "rbxassetid://99759198189491"
local command = "/e tvtime"
local playing = false
local currentTrack = nil
local lastPosition = nil
local function stopAnimation()
if currentTrack then
currentTrack:Stop()
currentTrack = nil
end
playing = false
lastPosition = nil
end
local anim = Instance.new("Animation")
anim.AnimationId = animationId
LocalPlayer.Chatted:Connect(function(message)
if message:lower() == command then
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator") or humanoid:WaitForChild("Animator")
stopAnimation()
currentTrack = animator:LoadAnimation(anim)
currentTrack.Looped = true
currentTrack:Play()
playing = true
local rootPart = character:WaitForChild("HumanoidRootPart")
lastPosition = rootPart.Position
end
end)
RunService.RenderStepped:Connect(function()
if playing then
local character = LocalPlayer.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart and lastPosition then
local currentPosition = rootPart.Position
if (currentPosition - lastPosition).Magnitude > 0.01 then
stopAnimation()
else
lastPosition = currentPosition
end
end
end
end
end)
but whenever i do /e tvtime on chat it says only r15 is allowed to emote on the chat, it takes a couple of tries until it works, but its not supposed to be like that and its meant to do the emote when i chat /e tvtime
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local animationId = "rbxassetid://99759198189491"
local command = "!tvtime" -- changed from "/e tvtime"
local playing = false
local currentTrack = nil
local lastPosition = nil
local function stopAnimation()
if currentTrack then
currentTrack:Stop()
currentTrack = nil
end
playing = false
lastPosition = nil
end
local anim = Instance.new("Animation")
anim.AnimationId = animationId
LocalPlayer.Chatted:Connect(function(message)
if message:lower() == command then
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator") or humanoid:WaitForChild("Animator")
stopAnimation()
currentTrack = animator:LoadAnimation(anim)
currentTrack.Looped = true
currentTrack:Play()
playing = true
local rootPart = character:WaitForChild("HumanoidRootPart")
lastPosition = rootPart.Position
end
end)
RunService.RenderStepped:Connect(function()
if playing then
local character = LocalPlayer.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart and lastPosition then
local currentPosition = rootPart.Position
if (currentPosition - lastPosition).Magnitude > 0.01 then
stopAnimation()
else
lastPosition = currentPosition
end
end
end
end
end)
Roblox intercepts /e so use custom prefix like !tvtime
R15-only emote error caused by default /e system
Unreliable triggering so avoid /e, use your own trigger
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local command = "!tvtime"
local animationId = "rbxassetid://507771019" -- replace with your own
local anim = Instance.new("Animation")
anim.AnimationId = animationId
local playing = false
local currentTrack = nil
local lastPosition = nil
local function stopAnimation()
if currentTrack then
currentTrack:Stop()
currentTrack = nil
end
playing = false
end
LocalPlayer.Chatted:Connect(function(message)
if message:lower() == command then
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChild("Animator")
stopAnimation()
if animator then
currentTrack = animator:LoadAnimation(anim)
else
currentTrack = humanoid:LoadAnimation(anim)
end
currentTrack.Looped = true
currentTrack:Play()
playing = true
lastPosition = character:WaitForChild("HumanoidRootPart").Position
end
end)
RunService.RenderStepped:Connect(function()
if playing then
local character = LocalPlayer.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart and lastPosition then
local currentPosition = rootPart.Position
if (currentPosition - lastPosition).Magnitude > 0.01 then
stopAnimation()
else
lastPosition = currentPosition
end
end
end
end
end)
Thanks, it works now, i also made it so it can do multiple but i dont have the emote id yet
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TextChatService = game:GetService("TextChatService")
local LocalPlayer = Players.LocalPlayer
local Emotes = {
["!tvtime"] = "rbxassetid://99759198189491",
--["!griddy"] = "rbxassetid://507771019",
--["!paranormals"] = "rbxassetid://507768133",
--["!paranormalswagtivity"] = "rbxassetid://507768133",
--["!ps"] = "rbxassetid://507768133",
}
local currentTrack = nil
local playing = false
local lastPosition = nil
local function stopAnimation()
if currentTrack then
currentTrack:Stop()
currentTrack = nil
end
playing = false
lastPosition = nil
end
local function playEmote(animId)
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid and (humanoid:FindFirstChildOfClass("Animator") or humanoid:WaitForChild("Animator"))
if not animator then return end
stopAnimation()
local anim = Instance.new("Animation")
anim.AnimationId = animId
currentTrack = animator:LoadAnimation(anim)
currentTrack.Looped = true
currentTrack:Play()
local rootPart = character:WaitForChild("HumanoidRootPart")
lastPosition = rootPart.Position
playing = true
end
TextChatService.OnIncomingMessage = function(message)
if message.TextSource then
local speaker = Players:GetPlayerByUserId(message.TextSource.UserId)
if speaker == LocalPlayer then
local text = message.Text:lower()
local animId = Emotes[text]
if animId then
playEmote(animId)
local channel = message.Metadata and message.Metadata.Channel
if channel then
local msgObj = TextChatService:FindFirstChild(channel)
if msgObj then
msgObj:DisplaySystemMessage("")
end
end
end
end
end
end
RunService.RenderStepped:Connect(function()
if playing then
local character = LocalPlayer.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart and lastPosition then
local currentPosition = rootPart.Position
if (currentPosition - lastPosition).Magnitude > 0.01 then
stopAnimation()
else
lastPosition = currentPosition
end
end
end
end
end)