Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to script an animation that allows your character to emote whenever you type /e?

--(Script Starts like this)-- local Module = require(2271580271)

local Animations = script.Animations:Clone()

Animations.Parent = game.ServerStorage

Module()

--(And then there is the Module Script underneath and attached to the regular script)--

local module = {

["orange"] = "rbxassetid://2271407199";

["fundance"] = "rbxassetid://2294429353";

}

return module

-----And what I'm really trying to do is make a script that allows you to play a pose whenever you type /e pose (not an emote nor an animation), basically a script that makes your humanoid stay like a statue, and then when you walk forward or backwards or either side, the animation automatically stops playing. Can someone help me script it out for me I already have the animations, I just need the script. Please and Thank You----

3 comments

1

why don't you just modify the animation script that does that for the other emotes?

1

It's honestly not that difficult. You would use the player's Chatted event and string.match().

0

^

2 answers

We're going to be learning about string manipulation. What I'm going to do is make it so that we'll check the message whenever the player chats, and if the start of it has "/e" we check the rest and see if we have the animation we want.

local Player = game:GetService("Players").LocalPlayer --We get the player
Player.Chatted:Connect(function(Message) --Everytime they chat, we get their message with "Message"
	if Message:sub(1,2) == "/e" then --We get the first 2 letters in the message and if it's "/e" we continue the code.
		if Message:sub(4,Message.len) == "ANIMATION NAME" then --We get the rest of the message and if it's equal to our animation name then we continue the code.
			local Animation = Instance.new("Animation") --We create an animation.
			Animation.AnimationId = "rbxassetid://IDHERE" --We edit the AnimationId to our animation.
			local Humanoid = Player.Character:FindFirstChild("Humanoid") --We get the humanoid.
			if Humanoid then --If the humanoid exists we continue the code.
				local playAnimation = Humanoid:LoadAnimation(Animation) --If the humanoid exists we load the animation.
				playAnimation:Play() --We play the animation.
			end
		end
	end
end)

Make sure this is in StarterPlayerScripts, and make sure it's a local script. That's all! Good luck coding the in the future!

1 comment

0

However this is NOT compatible with your module script. Try to edit it in a way where it is. Make sure to use "require"

So when using /e, we'll have to use a 'PlayerChatted' Event. I'll change up the script a bit, but hopefully it's still fine. If this 'Changed Script' is not usable by you (Because I will not be using module, require, etc.).

If you do choose to use this, you will require an 'Animation' inside the script, even if you are just going to define Animation as an ID (000000) or as script.Animation.

--[[MAKE SURE AN 'Animation' IS INSIDE THIS SCRIPT, EVEN IF YOU AREN'T GOING TO USE IT.

(It's choice if you will use ID like 00000, or use that Animation thing.)]]

  

local Z = false

local Animation1 = 2736626888 --[[This is ID for Orange Justice, feel free to use it. Or, you can change it to ur ID.

If you want it to script.Animation, feel free. It will still work, as I set Animation to that same ID, OR, again, change that ID to yours.]]

  


game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "/e orange justice" --[[Change "orange justice" to whatever you want.]] then
			local hum = player.Character:FindFirstChild("Humanoid") -- Defining Humanoid (A key point to play the animation, and to load it.)
			if Animation1 == script.Animation then --If your definition of Animation 1 was script.Animation, this will play. But if it wasn't, it would have functioned another way (In the else of if Animation1 == script.Animation)
				local ToPlay = hum:LoadAnimation(Animation1) --Load the animation of script.Animation or Animation1.
				ToPlay:Play() --Play the animation
				Z = true --Z now = true
				while Z == true and wait(1) do -- the While will only loop while Z is true, and to prevent timeout, I added 'and wait(1)'
					hum.Running:Connect(function(speed) -- Detects when it is running
						if speed > 0 then --If the speed is over 0 (0 Speed = not walking)
							ToPlay:Stop() --Then Stop animation
						end
					end)
				end
			else --But if it's an ID (Not script.Animation) then these lines will function.
				script.Animation.AnimationId = "rbxassetid://"..Animation1 --We can't just have it as the ID, because it's not an ASSETID, without concatenating that rbxassetid://
				local ToPlay = hum:LoadAnimation(script.Animation) --Loading the animation of script.Animation, as we changed the value of script.Animation to the numbers.
				ToPlay:Play() --Play
				Z = true --Z now = true, but it didn't earlier, since you made Animation1 an ID.
				while Z == true and wait(1) do -- To avoid timeout, we recommend adding 'and wait(1)', which is what I did.
					hum.Running:Connect(function(speed) -- Detects the humanoid running.
						if speed > 0 then --If the humanoid isn't walking (Speed = 0) then
							ToPlay:Stop() --Stop the animation
						end
					end)
				end
			end
			
		end
	end)
end)

I do have a model for this if you don't understand (Ask me for it if you need it), and if you do want the script with me using require, etc. then I might, but that is a bit unlikely. Hope this helped!

6 comments

0

Downvoted for copying Mr_Unlucky. He has already answered this question and there is no point in copying his answer at all.

0

no u

0

actually its not a copy don't you see it used PlayerAdded and in Mr_Unlucky already had a localssssdaad

0

While it isn't an exact copy, it does almost exactly the same thing, plus Lenny knew it was already up and chose to put up the same answer 3 hours later, I'm assuming for possibly stealing the rep.

0

Clearly it's not a copy

0

It hasn't been accepted. Plus, his script does not have the part where the animation stops when he moves, which is a request of the player. My script does not use message:sub. I did not define player as local Player = game:GetService("Players").LocalPlayer. I had to use LoadAnimation and Play, as they are compulsory for Animating. It's not copied, except for Load and Play, which is needed.

This discussion is preserved as it was. New answers, comments, and votes are closed.