I’m new to scripting, I want to put my own animations for the sitting which is randomized from a few different sitting animations. Does anyone know how to make this?
If you want to change the default animation you can do this with this script:
-- Server Script
local Players = game:GetService("Players") -- Our player service to use the PlayerAdded & CharacterAdded events.
local SitAnimID = 507776043 -- Set to your specified animation id to replace the default sit idle animation.
Players.PlayerAdded:Connect(function(Player) -- On player added
Player.CharacterAdded:Connect(function(Character) -- When character is added
local Animation = Character:FindFirstChild('SitAnim', true) -- Finding the sit animation in the character
Animation.AnimationId = ('rbxassetid://%s'):format(SitAnimID) -- Replacing animation id with yours.
end)
end)
Here is another helpful video that covers this topic:
I hope this helps you a little!
I made a seat in the bench i made and it dosen’t work. I had a normal script and i placed it inside and followed the script you had listed. It ended up having the character phase through the bottem and stand when it got on the seat.
What I would do is listen for the seated event on the client and check if the player is sitting then play the animation, so what I would do is make a local script and place it in starter character scripts, then you would do:
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animations = {}--add all the animation objects to the array
local CurrentAnim
for index, AnimationObj in ipairs(Animations) do
--loading in all the animations
Animations[index] = Humanoid:LoadAnimation(AnimationObj)
end
Humanoid.Seated:Connect(function(IsSitting, _)
if IsSitting then
CurrentAnim= Animations[math.random(1,#Animations)]
CurrentAnim:Play()
elseif CurrentAnim then
CurrentAnim:Stop()
end
end)
What does animation object mean?
go into studio and search for Animation, make one for all your animations and add the respective Id, to make the code simpler you could a make a folder in replicated storage will all of them called SittingAnimations, then do this:
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animations = game:GetService("ReplicatedStorage"):WaitForChild("SittingAnimations"):GetChildren()
local CurrentAnim
for index, AnimationObj in ipairs(Animations) do
--loading in all the animations
Animations[index] = Humanoid:LoadAnimation(AnimationObj)
end
Humanoid.Seated:Connect(function(IsSitting, _)
if IsSitting then
CurrentAnim= Animations[math.random(1,#Animations)]
CurrentAnim:Play()
elseif CurrentAnim then
CurrentAnim:Stop()
end
end)
I’m kinda new to studio so sorry if this is annoying.
How do you add the ID? Do you make a script and enter the script you put?