What do you want to achieve? A body cam system. I want to try and make it so, if you have the camera welded to your torso, and then you press B it plays an animation and sound then forces you into first person, also it toggles to turn on and off.
What is the issue? Having trouble finding out how to do it.
What solutions have you tried so far? Nothing much, searching for help first.
What you are looking for:
“Press B” → UserInputService : InputBegan : Enum.KeyCode.B
“If part is welded to torso” → player.Character:FindFirstChild(“The Part In Question”) : Has WeldObject inside it which is linked to Torso (or UpperTorso or HumanoidRootPart)
“Play an animation” → animation = Humanoid:LoadAnimation(animationTrack) : animation:Play()
Hope this helps!
you should use Humanoid.Animator:LoadAnimation() because Humanoid:LoadAnimation() is deprecated
Having problems doing that.
Is there something wrong with my code?
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character
– A sample function providing one usage of InputBegan
local function onInputBegan(input, gameProcessed)
if player.Character:FindFirstChild("BodyCam") then if input.UserInputType == Enum.UserInputType.MouseButton1 then end end end
Sometimes local scripts are ran before the character is added. So you will have to wait until the Character exists. People usually use
player.CharacterAdded:wait() but others have done
repeat wait() until player.Character both will get the job done.
Both get the job done but the second one is objectively bad. If it’s available, take the event-driven option over the loop always. For a majority of loops that you do (but not all), there’s a better event-driven way waiting somewhere.
local character = player.Character or player.CharacterAdded:Wait()
Thanks, got the script figured out… Just having trouble playing the animation.