So going based off your current script the error you are having is you are missing an end to finish the function.
So going off the code you have given this is how you'd want to set it up
local sit1 = workspace:FindFirstChild("SeatPart")
sit1.Touched:Connect (function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if hit and human then
local id = "rbxassetid://4781152374"
local Animation = Instance.new("Animation")
Animation.AnimationId = id
local Track = Humanoid:LoadAnimation(Animation)
Track:Play()
end
end)
This would play the animation when the player sits but not stop it if the player decided to get up.
So a better way to do this is using the humanoid States to check if the player is seated
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character ~= nil and workspace:FindFirstChild(Player.Name)
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local debounce = true
Humanoid.Changed:Connect(function()
local id = "rbxassetid://4781152374"
local Animation = Instance.new("Animation")
Animation.AnimationId = id
local Track = Humanoid:LoadAnimation(Animation)
if Humanoid.Sit == true and Humanoid:GetState() == Enum.HumanoidStateType.Seated and debounce == true then
debounce = false
Track:Play()
elseif Humanoid.Sit == false and Humanoid:GetState() ~= Enum.HumanoidStateType.Seated and debounce == false then
debounce = true
Track:Stop()
end
end)
Hopefully this answers your question or at least helps you some. Also if you want to always change the characters sitting animation to that one you can just copy the animate script while testing put it into starterCharacter scripts and just change the animation ID there
1 comment
Could you post your script so we can see what's going on? Also, please be a bit more specific and provide more detail in your question.