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.
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.
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.
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: