You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
- I don’t know what the problem is, but I just simply want this script to work so players would able to have fun with other people.
- What is the issue? Include screenshots / videos if possible!
- The script only works sometimes, if it doesn’t work it warns me with the message I put.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
- I’ve tried to put the eeVal variable before the task.wait(), I’ve tried putting the emote table in the emoteInfo table but still nothing, and I’ve searched on the devforums “script only works sometimes” or something along those lines, but still nothing related with my problem.
That’s all I can say, I’m pretty sure I’ve said everything with the scripts.
Client script:
local plr = game:GetService("Players")
local rps = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local run = game:GetService("RunService")
local emoteKey = Enum.KeyCode.G
local emoting = false
local rmodules = rps:WaitForChild("modules")
local events = rps:WaitForChild("events")
local player = plr.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local emotesModule = require(rmodules.emotes)
local eeVal = player:WaitForChild("plrStuff").emoteEquipped
task.wait(1)
local emote = emotesModule.emotesInfo[eeVal.Value]
if not emote then warn("player has non-existent emote!") return end
local anim = Instance.new("Animation")
anim.AnimationId = emote.animID
local loadedAnim = humanoid:LoadAnimation(anim)
loadedAnim.Looped = emote.looped
loadedAnim.Priority = Enum.AnimationPriority.Action
uis.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == emoteKey then
if character:GetAttribute("emoting") then
character:SetAttribute("emoting", nil)
local cmfh = character:FindFirstChild("cmfh")
if cmfh then
cmfh:Destroy()
end
humanoid.CameraOffset = Vector3.new(0, 0, 0)
loadedAnim:Stop(0.5)
events.player.playEmoteSfx:FireServer(eeVal.Value, true)
humanoid.WalkSpeed = 16
else
character:SetAttribute("emoting", true)
local cmfh = script.cmfh:Clone()
cmfh.Enabled = true
cmfh.Parent = character
loadedAnim:Play()
events.player.playEmoteSfx:FireServer(eeVal.Value, false)
humanoid.WalkSpeed = emote.walkspeed
end
end
end)
player.CharacterAdded:Connect(function(c)
character = c
humanoid = c:WaitForChild("Humanoid")
loadedAnim = humanoid:LoadAnimation(anim)
loadedAnim.Looped = emote.looped
loadedAnim.Priority = Enum.AnimationPriority.Action
end)
eeVal.Changed:Connect(function()
loadedAnim:Destroy()
loadedAnim = nil
task.wait(0.01)
emote = emotesModule.emotesInfo[eeVal.Value]
anim.AnimationId = emote.animID
loadedAnim = humanoid:LoadAnimation(anim)
loadedAnim.Looped = emote.looped
loadedAnim.Priority = Enum.AnimationPriority.Action
end)
Module:
local emotes = {}
emotes.emotesInfo = {}
local function addEmote(name, animID, sfxID, looped, walkspeed)
if not emotes.emotesInfo[name] then
emotes.emotesInfo[name] = {
["animID"] = animID,
["sfxID"] = sfxID,
["looped"] = looped,
["walkspeed"] = walkspeed,
}
else
warn(name .. " is already registered as an emote!")
end
end
addEmote("monster mash", "rbxassetid://16833088961", "rbxassetid://16833080135", false, 0)
addEmote("billy bounce", "rbxassetid://16486300210", "rbxassetid://16486245900", true, 3)
addEmote("unlock it", "rbxassetid://16877597900", "rbxassetid://16877840986", true, 3)
return emotes