How would I remove the elseif statements in this script?

Hey, I am currently making emotes, but I have ran into an issue of me spamming elseif’s for each new emote, which I really don’t want to do. How would I make it so that I don’t need to do this?

			if emoted == false and not status:FindFirstChild("Stun") and not blocking.Value == true and humanoid and profile ~= nil then
				stopeveryemote()
				if message == "/e sit" then
					emoted = true

					local sit = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.Sit)
					local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -10000000000; speedboost.Parent = status; Utilities.Debris(speedboost, 1.6)
					sit:Play()
					sit.Stopped:wait()
					speedboost:Destroy()
					local idle = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.SitIdle)
					table.insert(currentemotes, idle)
					idle:Play()
				elseif message == "/e lay" then
					local anim = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.Lay)
					local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -10000000000; speedboost.Parent = status; Utilities.Debris(speedboost, 1.6)
					anim:Play()
					anim.Stopped:wait()
					speedboost:Destroy()
					local idle = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.LayIdle)
					table.insert(currentemotes, idle)
					idle:Play()
				elseif message == "/e kazotsky" then
					local anim = humanoid:LoadAnimation(game.ServerStorage.NonClassEmotes.Kazotsky)
					local sound = Instance.new("Sound"); sound.SoundId = "rbxassetid://4339580587" sound.Looped = true; sound.Volume = .5; sound.Parent = Root
					local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -char.Humanoid.WalkSpeed * .6; speedboost.Parent = status
					table.insert(cancelactionemotes, speedboost)
					table.insert(cancelactionemotes, anim)
					table.insert(cancelactionemotes, sound)
					sound:Play()
					anim:Play()
				elseif message == "/e plunge" and profile.Data.Class == "BoStaff" then
					local anim = humanoid:LoadAnimation(game.ServerStorage.ClassAssets.ClassEmotes.BoStaff.Plunge); table.insert(cancelactionemotes, anim)
					local stun = Instance.new("IntValue"); stun.Name = "NoAttack"; stun.Parent = status; table.insert(cancelactionemotes, stun)
					local stun2 = Instance.new("IntValue"); stun2.Name = "NoSpecial"; stun2.Parent = status; table.insert(cancelactionemotes, stun2)
					local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -10000000000; speedboost.Parent = status; table.insert(cancelactionemotes, speedboost)
					anim:Play()
					wait(.5)
					local plungesound = script.Plunge:Clone(); plungesound.Parent = Root; plungesound:Play(); Utilities.Debris(plungesound, 3.5); table.insert(cancelactionemotes, plungesound)
					wait(.05)
					local kanji = script.PlungeKanji:Clone(); kanji.Parent = Torso; TweenService:Create(kanji.Symbol, TweenInfo.new(.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0), {ImageTransparency = 0}):Play()
						wait(.3)
					local tween = TweenService:Create(kanji, TweenInfo.new(.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0), {Size = UDim2.new(2, 0, 2.8, 0)}); TweenService:Create(kanji.Symbol, TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0), {ImageTransparency = 1}):Play() tween:Play(); tween.Completed:Wait()
					kanji:Destroy()
					stopeveryemote()
				end
			end
1 Like

You could structure the code like below, you may need to change some things but hopefully you get the drift:

local EmoteActions = {}

function EmoteActions:sit()
	emoted = true

	local sit = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.Sit)
	local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -10000000000; speedboost.Parent = status; Utilities.Debris(speedboost, 1.6)
	sit:Play()
	sit.Stopped:wait()
	speedboost:Destroy()
	local idle = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.SitIdle)
	table.insert(currentemotes, idle)
	idle:Play()
end

function EmoteActions:lay()
	local anim = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.Lay)
	local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -10000000000; speedboost.Parent = status; Utilities.Debris(speedboost, 1.6)
	anim:Play()
	anim.Stopped:wait()
	speedboost:Destroy()
	local idle = humanoid:LoadAnimation(game.ReplicatedStorage.FreeEmotes.LayIdle)
	table.insert(currentemotes, idle)
	idle:Play()
end

function EmoteActions:kazotsky()
	local anim = humanoid:LoadAnimation(game.ServerStorage.NonClassEmotes.Kazotsky)
	local sound = Instance.new("Sound"); sound.SoundId = "rbxassetid://4339580587" sound.Looped = true; sound.Volume = .5; sound.Parent = Root
	local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -char.Humanoid.WalkSpeed * .6; speedboost.Parent = status
	table.insert(cancelactionemotes, speedboost)
	table.insert(cancelactionemotes, anim)
	table.insert(cancelactionemotes, sound)
	sound:Play()
	anim:Play()
end

function EmoteActions:plunge()
	if profile.Data.Class ~= "BoStaff" then
		return
	end
	
	local anim = humanoid:LoadAnimation(game.ServerStorage.ClassAssets.ClassEmotes.BoStaff.Plunge); table.insert(cancelactionemotes, anim)
	local stun = Instance.new("IntValue"); stun.Name = "NoAttack"; stun.Parent = status; table.insert(cancelactionemotes, stun)
	local stun2 = Instance.new("IntValue"); stun2.Name = "NoSpecial"; stun2.Parent = status; table.insert(cancelactionemotes, stun2)
	local speedboost = Instance.new("IntValue"); speedboost.Name = "SpeedBoost"; speedboost.Value = -10000000000; speedboost.Parent = status; table.insert(cancelactionemotes, speedboost)
	anim:Play()
	wait(.5)
	local plungesound = script.Plunge:Clone(); plungesound.Parent = Root; plungesound:Play(); Utilities.Debris(plungesound, 3.5); table.insert(cancelactionemotes, plungesound)
	wait(.05)
	local kanji = script.PlungeKanji:Clone(); kanji.Parent = Torso; TweenService:Create(kanji.Symbol, TweenInfo.new(.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0), {ImageTransparency = 0}):Play()
	wait(.3)
	local tween = TweenService:Create(kanji, TweenInfo.new(.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0), {Size = UDim2.new(2, 0, 2.8, 0)}); TweenService:Create(kanji.Symbol, TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0), {ImageTransparency = 1}):Play() tween:Play(); tween.Completed:Wait()
	kanji:Destroy()
	stopeveryemote()
end

if emoted == false and not status:FindFirstChild("Stun") and not blocking.Value == true and humanoid and profile ~= nil then
	local emoteName = string.match(message, "^/e (%w+)$")
	if emoteName and typeof(EmoteActions[emoteName]) == "function" then
		stopeveryemote()
		EmoteActions[emoteName](EmoteActions)
	end
end
4 Likes