Scripting help at localscript

Hello everyone,

So, I’m trying to make a LocalScript in StarterPlayerScript that is J button activates/deactivates them. Where do I put the animation too? It’s looks green film icon idk

My script:

local UIS = game:GetService("UserInputService")
local Playing = false

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode = Enum.KeyCode.J then
        if Playing == false then
            Playing = true
            Run.RunAnim:Play()
        elseif Playing == true then
            Playing = false
            Run.RunAnim:Stop()
        end
    end
end)

1 Like

I don’t see anything wrong with the code you provided, except it seems like Run is excluded.

Also, what’s the problem exactly? If you could provide the full code and details as to what the issue is I can help you more. :slight_smile:

2 Likes

So, the animation should be named to “RunAnim” and be put under the localscript?

No, you do not put animations into local scripts, you only put them on rigged models. So, the script is fine, no need to change anything unless there are errors

2 Likes

If you’re trying to play an animation for a character, you need to load the animation onto the humanoid first:

local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local Player = Players.LocalPlayer
local Playing = false
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local AnimationTrack = Humanoid:LoadAnimation(Run.RunAnim)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode = Enum.KeyCode.J then
        if Playing == false then
            Playing = true
            AnimationTrack:Play()
        elseif Playing == true then
            Playing = false
            AnimationTrack:Stop()
        end
    end
end)

References:

2 Likes