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

im trying to put a specific animation for one specific sit and it dosen't work ?

Im gonna try to be more specific here sorry for my grammar im french.

heres the Local Script im using , doe i saw that when i put my mouse over it it says :

(Expected 'end'(to close'function' at line 3))

local sit1 = workspace.SeatPart

sit1.Touched:Connect (function(hit) local human = hit.Parent:FindFirstChild("Humanoid") if hit and human then id = "http://www.roblox.com/asset/?id=4781152374"

end

1 comment

0

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.

1 answer

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) --Extended out you code to make it look nicer to read
	local human = hit.Parent:FindFirstChild("Humanoid") 
		if hit and human then
		local id = "rbxassetid://4781152374"--the more proper way of setting Id's
		local Animation = Instance.new("Animation") -- create a new animation object
		Animation.AnimationId = id --set the animation ID

		local Track = Humanoid:LoadAnimation(Animation)
		Track:Play()-- Play the animation
		end
end)--This fixes the error for not having the end on the function

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)--wait until a character is found (you can also put the local script into character scripts and remove this line)
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local debounce = true

Humanoid.Changed:Connect(function()
local id = "rbxassetid://4781152374"--the more proper way of setting Id's
		local Animation = Instance.new("Animation") -- create a new animation object
		Animation.AnimationId = id --set the animation ID

		local Track = Humanoid:LoadAnimation(Animation)

    if Humanoid.Sit == true and Humanoid:GetState() == Enum.HumanoidStateType.Seated and debounce == true then--checks if the player is sitting down on a chair
        debounce = false
	Track:Play()-- Plays the animation when the player sits down

elseif Humanoid.Sit == false and Humanoid:GetState() ~= Enum.HumanoidStateType.Seated and debounce == false then
        debounce = true
	Track:Stop()-- Stops the animation when the player gets up
    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

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