How would I be able to make a keybind function play an animation for one character specifically?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve a system where, if you’re morphed into a character, it checks if you’re that character and when you press a key, it play animation.
  2. What is the issue? Include screenshots / videos if possible!
    None, I’m new to scripting.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried some kits, but either the scripts weren’t tested or were rushed.

Anyways, any help is welcome. I only know a bit of things like variables and stuff, but not how to position them in an actual script.

i’d suggest looking into morphs tutorial
(as i cant provide you a script for that since idk how)

and inserting a local script to that character with a UserInputService

or a Context Action Service

which will detect if player has pressed any specific buttons

To check the morph, have so many ways to do this, you can put a StringValue inside the morph and set the Value of the StringValue to the morph name, then you use a script to check the value of the StringValue

LocalScript exemple:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

--This is a service to check player inputs, check the docs of this service to know more.
local UserInputService = game:GetService("UserInputService")

--[[
	Everytime the player press a button or so something in the game, will fire a input and will
	call this function below.
--]]
UserInputService.InputBegan:Connect(function(input, interaction)
	--Checking if the player dont fired a input while interacting with something in the game
	if not interaction then
		if input.KeyCode == Enum.KeyCode.R then
			if Character then
				--Checking if StringValue exist in the character, you can name with what name you want, but you will need to change the name here too
				if Character:FindFirstChild("StringValue") then
					if Character.StringValue.Value == "Player" then
						--do something...
					elseif Character.StringValue.Value == "idk" then
						--do something...
					end
				end
			end
		end
	end
end)

Morph:
image

UserInputService docs: UserInputService | Documentation - Roblox Creator Hub

1 Like

Thank you for letting me know about String Values! I’ll add some more code and see if this could work!

I’ll read the context article because I think that’s the area I need the most help with.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.