So I tried to do it but all my tries failed, here is the script I wanna is being runned if I sit on an seat :
Animation = Instance.new(“Animation”)
Animation.Parent = game.Workspace
Animation.AnimationId = “http://www.roblox.com/asset/?id=ID HERE” --Where It Says ID HERE, Place Your Animation Id
local Player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key)
for i, v in pairs(game.Players:GetChildren()) do
if key == “f” then – THIS IS UR KEY U WANA CHANGE IT CHANGE F TO SOMETHING ELSE
local AnimationTrack = Player.Character.Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
end
end
end)
local seat = script.Parent
seat.ChildAdded:Connect(function()
Animation = Instance.new(“Animation”)
Animation.Parent = game.Workspace
Animation.AnimationId = “http://www.roblox.com/asset/?id=7006749762” --Where It Says ID HERE, Place Your Animation Id
local Player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key)
for i, v in pairs(game.Players:GetChildren()) do
if key == “f” then – THIS IS UR KEY U WANA CHANGE IT CHANGE F TO SOMETHING ELSE
local AnimationTrack = Player.Character.Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
end
end
end)
end)
is what i did and doesnt works
local function onSit()
local seat = script.Parent
seat.ChildAdded:Connect(function()
Animation = Instance.new(“Animation”)
Animation.Parent = game.Workspace
Animation.AnimationId = “http://www.roblox.com/asset/?id=7006853886” --Where It Says ID HERE, Place Your Animation Id
local Player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key)
for i, v in pairs(game.Players:GetChildren()) do
if key == “X” then – THIS IS UR KEY U WANA CHANGE IT CHANGE F TO SOMETHING ELSE
local AnimationTrack = Player.Character.Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
end
end
end)
end)
end
If you need to sit and play animation after pressing X. You need to add UserInputService or ContexActionService. Read more about them on DevHub (link).
And, please, use special code box for code.