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

It is supposed to do the action when you press T + click on the target player but isn't working?

The script is like a magic move that you can use on others and I want to be able to press T then click on the target and work and this is the script I am currently using:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")


local anim = Instance.new("Animation")
anim.AnimationId = "https://www.roblox.com/asset/?id='5480157154'


mouse.KeyDown:connect(function(key)
	  if key == "t" then
   local playAnim = humanoid:LoadAnimation(anim)
   playAnim:Play()

    end
end)

If you know please do answer below as I am eager to find out. the solution.

2 comments

0

use userinputservice

0

dont use keydown , use UserInputService, you literally required it

2 answers

Next time, please use UserInputService as KeyDown is deprecated, however upon reading your script I have seen that you made a mistake about the animation Id.

Please replace:

anim.AnimationId = "https://www.roblox.com/asset/?id='5480157154'

To:

anim.AnimationId = "https://www.roblox.com/asset/?id=5480157154"

Make sure that you own the animation otherwise it won't work. Roblox doesn't allow animation-sharing to others.

Try changing the parent of your animation inside the script:

anim.Parent = script

1 comment

0

Changing the parent of the anim will not do anything.

Might be the way you're detecting the keydown. Also, use rbxassetid instead of the way you did it.

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")


local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://5480157154'


UIS.InputBegan:Connect(function(input, process)
	if not process then
		if input.KeyCode == Enum.KeyCode.T then
			local playAnim = humanoid:LoadAnimation(anim)
	   		playAnim:Play()
		end
	end
end)

Cheers, Zander

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