Hello,
I wrote a script to make a stand that is supposed to be behind the player do an animation when the player presses the E key. For reasons unknown to me, the script does not work. The stand model has a humanoid and an animator inside the humanoid. I tried to put the script in StarterCharacterScripts and StarterPlayerScripts, but it does not work.
Here is the script :
(Between it’s a LocalScript)
local UserInputService = game:GetService("UserInputService")
local animationId = "rbxassetid://13488453864"
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.E then
local humanoid = game.Players.LocalPlayer.Character.FindFirstChild("Stand").Humanoid
humanoid:LoadAnimation(animationId):Play()
end
end
UserInputService.InputBegan:Connect(onKeyPress)
I think you should refer to the animator as well. I think you should refer to the animator as well. also I see you have an animationcontroller so why load the animation with a humanoid?
edit: you have to create an animation and set the AnimationIId with the animation id of your choice
local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local Id = "rbxassetid://13488453864"
local animationId = Instance.new("Animation")
animationId.AnimationId = Id
animationId.Parent = player
local humanoid = player.Character.WaitForChild("Stand").Humanoid.Animator:LoadAnimation(animationId)
function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.E then
humanoid:Play()
end
end
UserInputService.InputBegan:Connect(onKeyPress)
Make sure to replace “rbxassetid://13488453864” with the correct animation ID you want to use.
local UserInputService = game:GetService(“UserInputService”)
local animationId = “rbxassetid://13488453864” – Replace with the correct animation ID
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.E then
local character = game.Players.LocalPlayer.Character
local stand = character:FindFirstChild(“Stand”)
if stand and stand:IsA("Model") then
local humanoid = stand:FindFirstChildOfClass("Humanoid")
local animator = humanoid and humanoid:FindFirstChildOfClass("Animator")
if humanoid and animator then
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
end
end
end