Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make custom animation/pose for seat item?

I am coming from here https://scriptinghelpers.org/questions/3330/this-script-only-works-sometimes and although that person's issue was solved, mine still is not. I am trying to make a custom sitting animation using a seat from roblox studio. Here is the scrip i have: local seat = script.Parent

local seat = script.Parent

function SeatIsSatIn(hit)
if hit.Parent:FindFirstChild("Humanoid") then
    local character = hit.Parent
    local humanoid = character.Humanoid
    wait(0.2) -- Wait a little bit so that the character has time to sit.
    if humanoid:GetState() == Enum.HumanoidStateType.Seated then -- Make sure the 	humanoid is sitting
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/asset/?id=3788531001"
        local  track = humanoid:LoadAnimation(animation)
        track:Play()

        local function StateChanged(oldState, newState)
            if newState ~= Enum.HumanoidStateType.Seated then
                track:Stop()
            end
        end
        humanoid.StateChanged:connect(StateChanged)
  		end
	end
end

seat.Touched:connect(SeatIsSatIn)

I need for the animation to work every time and not just sometimes. Currently one in every 5-6 tries will play the animations and on the off times it is just a normal sit. Anyone know how to do this?

1 answer

Make sure it's a normal script, make sure it's in the seat and make sure the animation is looped. I've had the same problem once before, so I'll give you my script to use. If it doesn't work for some reason, then I'll try to help.

--Variables
local sitAnims = {0, 0} --Put the same animation id twice. 

local seat = script.Parent
local playingAnim 

--Making the ID
local newAnim = Instance.new('Animation')
newAnim.AnimationId = 'rbxassetid://'..sitAnims[math.random(#sitAnims)]

--Making the player sit
seat.Changed:Connect(function(property)
	if property == 'Occupant' then
		local occupant = seat.Occupant
		if not occupant then if playingAnim then playingAnim:Stop() return end end
		playingAnim = occupant:LoadAnimation(newAnim)
		playingAnim:Play()
	end
end)

--Making sure the player can jump
humanoid.StateChanged:Connect(function(old, new)
	end)
if new == Enum.HumanoidStateType.Jumping then	
	end

This discussion is preserved as it was. New answers, comments, and votes are closed.