How do I give basic humanoid animations to the character? And make sure the character can’t move it too.
Sorry, but i dont understand you
Are you referring to the animate script?
You can use this npc and change the animations if you want:
:LoadAnimation()
and AnimationPriority
.
For an example script, it could look something like this:
-- LocalScript inside of StarterCharacterScripts
local player = game.Players.LocalPlayer -- get the local player
local character = player.Character or player.CharacterAdded:Wait() -- get the character
local humanoid = character:WaitForChild("Humanoid") -- get the humanoid
local animator = humanoid:FindFirstChildOfClass("Animator") -- find the animator
if not animator then -- animator not found, create new animator
animator = Instance.new("Animator")
animator.Parent = humanoid
end
local animation = animator:LoadAnimation(YOUR_ANIMATION_HERE) -- path to your Animation object
Animation.Priority = Enum.AnimationPriority.Action -- highest priority (will override everything)
Animation:Play() -- plays the animation
Best practice to use the player’s Animator, and not the Humanoid for :LoadAnimation()
. :LoadAnimation()
for the Humanoid is deprecated.
Is there a way to make it so other players can’t move the NPC? I still want the animations to play.
Sure, if you use this npc, create server script for everyone to see.
No I mean to make the npc not movable. If I go to the humanoid, no collisions should occur. I should be able to go through the NPC.
Google is your friend.
add animations to the NPC and anchor the HumanoidRootPart, so the NPC is still going to have animations but not be moved
i am concerned about the going through NPC part lol
That didn’t do anything and HumanoidRootPart anchored on disables the animations.
Try setting your AnimationPriority. Otherwise, create a CollisionGroup for your players and another for your NPC. Then disable the collisions for those two groups.
What is the problem?
The humanoid can move and will not collide with players.
What does not work?
Fixed by doing
local physics = game:GetService("PhysicsService")
physics:CreateCollisionGroup("playersGroup")
physics:CreateCollisionGroup("npcsGroup")
--Sets up the collision groups ^
physics:CollisionGroupSetCollidable("playersGroup", "npcsGroup", false)
--Making the groups cancollide false
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(char)
for _, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
physics:SetPartCollisionGroup(v, "playersGroup")
end
end
end)
end)
--waits for char to load in then sets its parts to the collision group
for _, v in pairs(workspace:WaitForChild("Chefs"):GetChildren()) do
for _, part in pairs(v:GetChildren()) do
if part:IsA("BasePart") then
physics:SetPartCollisionGroup(part, "npcsGroup")
end
end
end