Where do I put this script

Local scripts dont work in StarterPlayer and I coded a script but I dont know where to put it
This script is enabling animations I currently have it as a local script in StarterPlayer

local function animateMob(object)
      local humanoid = object:WaitForChild("Humanoid")
      local animationsFolder = object:WaitForChild("Animations")

      if humanoid and animationsFolder then
            local walkAnimation = animationsFolder:WaitForChild("Walk")
            if walkanimation then
                    local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
                    local walkTrack = animator:LoadAnimation(walkAnimation)
                   walkTrack:Play()
              end
       else
             warn("No humanoid/animation folder for", object.Name)
       end
end

workspace.Mobs.ChildAdded:Connect()

Please help I’m trying to make the game before sun down.

1 Like

LocalScripts won’t work when directly placed in the StarterPlayer service, but it can be placed into StarterPlayerScripts.

Any LocalScripts placed there are cloned and added to each player’s PlayerScripts container upon joining the game, which is one of the places that LocalScripts can run.

Will it be run on the player though?

Yup! Any LocalScript placed there is given to each individual player when they join the game, and once the game adds it to the PlayerScripts folder that is specific to that player, the code within that LocalScript will run independently for them.

I linked to several resources from the Roblox Creator Documentation in my previous post that you can read to learn more.

1 Like

I dont want it to run on the player I want it to run on the mobs(its an animation) but I dont know where to place it I was wondering if I could place it anywhere else so it would function on the mobs. You explained to me that they wouldn’t work but I was asking where else could I place this script for it to function and animate the mobs.

I was clarifying that the code of the LocalScript would run locally when it’s a descendant of the Player object in a container such as the PlayerScripts.

The code will not be run on the player object itself. Sorry if my prior response made it sound like that’s what I was suggesting!


If you move the LocalScript that contains the code in your original post to the StarterPlayerScripts without making any changes to it, it will run it as you intended, listening for items to be added to the “Mobs” folder. This is what I recommended in my original response.

1 Like

Ah, but after you change where the LocalScript is placed, the last line of code would need to be revised to run the “animateMob” function, because the event is not currently being connected to it:

It would be revised to the following:

workspace.Mobs.ChildAdded:Connect(animateMob)
2 Likes

Thank you so much and sorry if I was seen as rude I was just panicking because the sun was about to go down, the animations now work.

1 Like

No worries! I knew there was just a little bit of miscommunication right before we got to the right answer and I was happy to continue helping.

Best of luck with your game :smile:

1 Like

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